Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: making first letter of all words in array upper case

by seattlejohn (Deacon)
on Dec 31, 2002 at 20:05 UTC ( #223443=note: print w/replies, xml ) Need Help??

in reply to making first letter of all words in array upper case

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:

foreach my $word (@words) { $word = ucfirst $word }

*--assuming you're in list context, which in this case you are

        $perlmonks{seattlejohn} = 'John Clyman';

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://223443]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2023-01-27 02:09 GMT
Find Nodes?
    Voting Booth?

    No recent polls found