The stupid question is the question not asked | |
PerlMonks |
Re: making first letter of all words in array upper caseby seattlejohn (Deacon) |
on Dec 31, 2002 at 20:05 UTC ( [id://223443]=note: print w/replies, xml ) | Need Help?? |
Task 1 is pretty easy thanks to the magic of map. Just @words = map {ucfirst $_} @words would do the trick.
Basically map takes a block and a list, and applies the code in the block to every element in the list (substituting each list element into $_). Then it returns the resulting list.* If you want to do it in an explicit foreach loop, as in your sample code above, you could write it this way:
*--assuming you're in list context, which in this case you are $perlmonks{seattlejohn} = 'John Clyman';
In Section
Seekers of Perl Wisdom
|
|