Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Capitalize the 1st letter of each word

by Zaxo (Archbishop)
on Jan 15, 2004 at 20:06 UTC ( [id://321655]=note: print w/replies, xml ) Need Help??


in reply to Capitalize the 1st letter of each word

A regex is best suited to altering the array in place s/(\w)(\w*)/\U$1\E$2/ for @array; You can use a regex, but to make a new array with initial caps, ucfirst is handier, my @arrayl = map {ucfirst} @array; The regex can also be applied to a string with the /g flag

$_ = 'foo bar foobar barfoo 1 2 3'; s/(\w)(\w*)/\U$1\E$2/g; print; # Foo Bar Foobar Barfoo 1 2 3

After Compline,
Zaxo

Replies are listed 'Best First'.
Capitalize the 1st letter of each word
by flatline (Novice) on Jan 15, 2004 at 21:13 UTC
    An easier regex/substitution would be:
    my @array = qw/one Two three four five/; s/(.)/\u\L$1/ for @array;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (1)
As of 2024-04-25 04:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found