in reply to Spelled out numbers to numerical equivalent function

Ahh, now it looks as though I spoke too soon. For instance in a case like this test below:
#!/usr/bin/perl + + use Lingua::EN::Numericalize; + + print str2nbr('First, Second, Third, Twentythird');


It prints '123' not what I would want to print which is:
'1st, 2nd, 3rd, 23rd'
It seems as if this problem is still a bit stickier. At least the package is a step in the right direction.

Thank you -- Akira the humble

Replies are listed 'Best First'.
Re^2: Spelled out numbers to numerical equivalent function
by mayhem (Hermit) on Apr 12, 2005 at 18:55 UTC
    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