Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by seattlejohn (Deacon)
on Dec 31, 2002 at 20:05 UTC ( [id://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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-03-28 19:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found