Another way:
This takes advantage of the fact that a city name or portion thereof looks like a state/provincial zip/postal code abbreviation (but not an ISO one, apparently). See \u \L and their friends \U \l \F \Q \E in Quote and Quote-like Operators.c:\@Work\Perl>perl -wMstrict -le "for my $s (' bElLmOnT NY', ' NeW yOrK NY', ' sAuLt StE. mArIe MI',) { my $t = $s; my $name = qr{ [[:alpha:]]+ [.]? }xms; $t =~ s{ \b ($name) (?= \s+ $name) } {\u\L$1}xmsg; print qq{'$s' -> '$t'}; } " ' bElLmOnT NY' -> ' Bellmont NY' ' NeW yOrK NY' -> ' New York NY' ' sAuLt StE. mArIe MI' -> ' Sault Ste. Marie MI'
Give a man a fish: <%-(-(-(-<
In reply to Re: Capitalize only the first letter of the first word in a string
by AnomalousMonk
in thread Capitalize only the first letter of the first word in a string
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |