in reply to making first letter of all words in array upper case
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!my @friends = split / /, $raw_friends; # space in split() is fine $_ = ucfirst for @friends;
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
|
|---|