sub reform { my $line = shift; my @toret; foreach my $word (split(/\b/,$line)) { if (lc($word) eq 'mrs') { $word = "Mrs."; } elsif (length($word) > 2) { $word =~ s/^(.)(.*)/uc($1).lc($2)/se; } elsif (lc($word) eq 'mr') { $word = "Mr."; } push (@toret, $word); } return join("",@toret); }
adrade@antigone:~$ perl -e 'print ucfirst("il"),"\n"' Il adrade@antigone:~$ perl -e 'print ucfirst("HELLO"),"\n"' HELLO adrade@antigone:~$ perl -e 'print ucfirst("mrs"),"\n"' Mrs # I put reform() in ref.pm adrade@antigone:~$ perl -e 'use ref; print reform("il"),"\n"' il adrade@antigone:~$ perl -e 'use ref; print reform("HELLO"),"\n"' Hello adrade@antigone:~$ perl -e 'use ref; print reform("Mrs"),"\n"' Mrs.
--
By a scallop's forelocks!
In reply to Re: Capitalize the first letter of each word
by Adrade
in thread Capitalize the first letter of each word
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |