in reply to Re: RegExp Capitalization of Entry
in thread RegExp Capitalization of Entry
You will have to expand %Exceptions as you find/think of them.# Title case except for some special words use strict; my %Exceptions = ( "and" => "and", "the" => "the", "or" => "or", "zztop" => "ZZtop", "ii" => "II" ); while (<DATA>) { my @Results = map { (defined ( $Exceptions{lc($_)})) ? $Exceptions{lc($_)} : ucfirst ( lc ( $_ ) ) } split ( /\s+/, $_ ); #captialize first word regardless substr($Results[0],0,1, uc substr($Results[0],0,1)); print join ( " ", @Results ) . "\n"; } __DATA__ red hot chili peppers by the way zztop greatest hits vol. II the beatles the white album disc II __OUTPUT__ Red Hot Chili Peppers By the Way ZZtop Greatest Hits Vol. II The Beatles The White Album Disc II
__UPDATE__
added code to capitalize first character of first word.
--
flounder
|
---|