Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/perl/bin/perl -w use strict; ## capitalize each word's first character, downcase the rest my $test = cap("o'tools"); my $test2 = cap("mcdonalds"); my $test3 = cap("mcmaster"); my $test4 = cap("MCENROE"); print "**1-$test**\n"; # should print "O'Tools" print "**2-$test2**\n"; #should print "Mc Donalds" print "**3-$test3**\n"; #should print "Mc Master" print "**4-$test4**\n"; #should print "Mc Enroe" sub cap { my $case = shift || ''; $case =~ s/(\w+)/\u\L$1/g; return $case; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capitalization Case Help!
by Corion (Patriarch) on Sep 15, 2010 at 19:33 UTC | |
|
Re: Capitalization Case Help!
by Your Mother (Archbishop) on Sep 15, 2010 at 20:05 UTC | |
|
Re: Capitalization Case Help!
by kennethk (Abbot) on Sep 15, 2010 at 20:31 UTC | |
|
Re: Capitalization Case Help!
by graff (Chancellor) on Sep 16, 2010 at 01:37 UTC | |
by AnomalousMonk (Archbishop) on Sep 16, 2010 at 03:22 UTC |