in reply to Re^2: Capitalize First Letter of Each Word
in thread Capitalize First Letter of Each Word
It does, except it doesn't work:
my @a = ("a sTrinG\n" ); s#(.)(\w+ ?)#\U\1\L\2#g for @a; print @a; __END__ a string
Two things are happening here: The first is that this requires each word to be two characters or more (so it fails on the initial "a"). The second is that the . can match a space, so " sTrinG" fails because \1 contains a space.
I suggest
s{ \b(\w+) }{\u\L$1}gx;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: Capitalize First Letter of Each Word
by holli (Abbot) on Jun 30, 2005 at 14:14 UTC | |
by suaveant (Parson) on Jun 30, 2005 at 14:36 UTC |