FAQ
Hello,


The following uppercase'S the whole string, when all I want is the first letter.


&uppercase($bears->{"rec$n"}{name}), uc($bears->{"rec$n"}{type}) # works but caps the whole string
}

u\$bears->{"rec$n"}{type} # does not work...


sub uppercase{
($s) = @_;
\u$s = scalar $s; ## does not work
return $s;
}


another version:

sub uppercase{
($s) = @_;

return uc($s); # works but caps the whole string
}


lastly, in this hash of hashs..

$bears = {

rec1 => {
type => 'sweater',
name => 'sweaterie',
color => 'golden brown',
food => 'mixed beries',
},


one of many... more recs heres


}


is $ (scalar) $bears, correct? should not be %bears


How would I get the lenght of $bears if I wanted to a:

for (0 .. # true lenght of $bears )

and as it is, I can not do the following, that you would use will normal hashs

foreach my $key (sort keys %bears ) {


Thanks & good day,

Dave G.
-------

*====================================================*
* Cora Connection Your West African Music Source *
* http://www.coraconnection.com/ *
* Resources, Recordings, Instruments & More! *
*====================================================*

Search Discussions

  • Mooney Christophe-CMOONEY1 at Jul 16, 2001 at 5:30 pm
    use ucfirst instead of uc

    -----Original Message-----
    From: David Gilden
    Sent: Monday, July 16, 2001 12:28 PM
    To: beginners@perl.org
    Subject: upper-casing the first char & hashs of hashs


    Hello,


    The following uppercase'S the whole string, when all I want is the first
    letter.


    &uppercase($bears->{"rec$n"}{name}), uc($bears->{"rec$n"}{type}) # works
    but caps the whole string
    }

    u\$bears->{"rec$n"}{type} # does not work...


    sub uppercase{
    ($s) = @_;
    \u$s = scalar $s; ## does not work
    return $s;
    }


    another version:

    sub uppercase{
    ($s) = @_;

    return uc($s); # works but caps the whole string
    }


    lastly, in this hash of hashs..

    $bears = {

    rec1 => {
    type => 'sweater',
    name => 'sweaterie',
    color => 'golden brown',
    food => 'mixed beries',
    },


    one of many... more recs heres


    }


    is $ (scalar) $bears, correct? should not be %bears


    How would I get the lenght of $bears if I wanted to a:

    for (0 .. # true lenght of $bears )

    and as it is, I can not do the following, that you would use will normal
    hashs

    foreach my $key (sort keys %bears ) {


    Thanks & good day,

    Dave G.
    -------

    *====================================================*
    * Cora Connection Your West African Music Source *
    * http://www.coraconnection.com/ *
    * Resources, Recordings, Instruments & More! *
    *====================================================*

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
  • Wagner-David at Jul 16, 2001 at 5:32 pm
    replace uc with ucfirst.

    Wags ;)

    -----Original Message-----
    From: David Gilden
    Sent: Monday, July 16, 2001 10:28
    To: beginners@perl.org
    Subject: upper-casing the first char & hashs of hashs


    Hello,


    The following uppercase'S the whole string, when all I want is the first
    letter.


    &uppercase($bears->{"rec$n"}{name}), uc($bears->{"rec$n"}{type}) # works
    but caps the whole string
    }

    u\$bears->{"rec$n"}{type} # does not work...


    sub uppercase{
    ($s) = @_;
    \u$s = scalar $s; ## does not work
    return $s;
    }


    another version:

    sub uppercase{
    ($s) = @_;

    return uc($s); # works but caps the whole string
    }


    lastly, in this hash of hashs..

    $bears = {

    rec1 => {
    type => 'sweater',
    name => 'sweaterie',
    color => 'golden brown',
    food => 'mixed beries',
    },


    one of many... more recs heres


    }


    is $ (scalar) $bears, correct? should not be %bears


    How would I get the lenght of $bears if I wanted to a:

    for (0 .. # true lenght of $bears )

    and as it is, I can not do the following, that you would use will normal
    hashs

    foreach my $key (sort keys %bears ) {


    Thanks & good day,

    Dave G.
    -------

    *====================================================*
    * Cora Connection Your West African Music Source *
    * http://www.coraconnection.com/ *
    * Resources, Recordings, Instruments & More! *
    *====================================================*

    --
    To unsubscribe, e-mail: beginners-unsubscribe@perl.org
    For additional commands, e-mail: beginners-help@perl.org
  • Paul at Jul 16, 2001 at 5:47 pm

    --- David Gilden wrote:
    The following uppercase'S the whole string, when all I want is the
    first letter.
    sub uppercase{
    ($s) = @_; return uc($s); # works but caps the whole string
    }
    Others have already said to use ucfirst. =o)
    lastly, in this hash of hashs..

    $bears = {

    rec1 => {
    type => 'sweater',
    name => 'sweaterie',
    color => 'golden brown',
    food => 'mixed beries',
    },


    one of many... more recs heres


    }


    is $ (scalar) $bears, correct? should not be %bears
    scalar $bears is correct if you want a reference, which is how you were
    using it before.

    to say $bears->{food} is correct if that's what you want.

    If instead you just want a normal hash, change $bears to %bears, but
    you must also change the {} around the contents to (), and the
    references like $bears->{food} to $bears{food}
    How would I get the lenght of $bears if I wanted to a:

    for (0 .. # true lenght of $bears )
    Why would you do this?
    It isn't an array....
    Do you want to know how many keys there are?
    try
    scalar keys %bears
    and as it is, I can not do the following, that you would use will
    normal hashs

    foreach my $key (sort keys %bears ) {
    If you're using the reference syntax, dereference it in the loop
    structure.

    for my $key ( sort keys %{$bears} ) { # . . .

    __________________________________________________
    Do You Yahoo!?
    Get personalized email addresses from Yahoo! Mail
    http://personal.mail.yahoo.com/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJul 16, '01 at 5:27p
activeJul 16, '01 at 5:47p
posts4
users4
websiteperl.org

People

Translate

site design / logo © 2022 Grokbase