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 |