in reply to Re: Spelled out numbers to numerical equivalent function
in thread Spelled out numbers to numerical equivalent function

There is a easy way to remedy this...
for my $text (qw/first third thirteenth twentyfirst twentysecond oneh +undredone onehundredtwelve onehundredeleven/) { my $number = str2nbr($text); my $sufix = 'th'; if ( $number =~ /^1$/ or $number =~ /[^1]1$/ ) { $sufix = 'st'; } if ( $number =~ /^2$/ or $number =~ /[^1]2$/ ) { $sufix = 'nd'; } if ( $number =~ /^3$/ or $number =~ /[^1]3$/ ) { $sufix = 'rd'; } print $number . $sufix, $/; }
and i get 1st, 3rd, 13th, 21st, 22nd, 101st, 112th, 111th I believe this will work for all your cases, i would test it more though. ED: changed a var name, didn't like it after i looked at again