Perl-Sensitive Sunglasses | |
PerlMonks |
Re: making first letter of all words in array upper caseby SuperCruncher (Pilgrim) |
on Dec 31, 2002 at 20:02 UTC ( [id://223442]=note: print w/replies, xml ) | Need Help?? |
Well, first of all, an observation: how is the user meant to know how to separate multiple friends? Further, how are they even meant to know that you actually can send the message to multiple friends? I know you've written "friends", but I think you really mean either "friend's" or "friends'", but anyway, enough of this English pedantry. Also, this way of entering friend information is highly error prone: the names and e-mail address could easily get out of sync (e.g. what if the user enters 3 friend names, but only two e-mail addresses?) Generally, you've got the right idea, but you just seem a bit confused about Perl syntax. In your code, you are doing @from = ucfirst($from). What you're doing is effectively wiping out the array (as you're assigning to @from with the initial-uppercased version of the first element. You probably want to do something like this instead: Note the $_ = ucfirst for @friends code: it loops through the @friends array, assigning each element in turn to the $_ variable. We are overwriting that variable with the uppercased version of it (like many Perl built-ins, ucfirst operates on $_ by default). In foreach loops, when you modify the variable that holds the current element, this modifies the array. As the docs say, this is considered a feature! From your confusion about @friends and $friends, you've shown that you haven't really learnt Perl in the best way (no offense intended). The difference between @friends and $friends in Perl is pretty fundamental, so it's important that you can understand it. I'd buy one of the books mentioned at the learn Perl site, and work through it. Don't worry, your investment in Perl will pay back very quickly! Edit: fixed typo - changed uc to ucfirst
In Section
Seekers of Perl Wisdom
|
|