Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

RE: RE: Re: Number to Speech

by nuance (Hermit)
on Aug 22, 2000 at 15:23 UTC ( #28989=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Number to Speech
in thread Number to Speech

If you've got the ordinal then the cardinal is relatively easy, just roll your own. something like:
#!/usr/bin/perl -w use strict; my @examples = ("one", "two", "three", "nine", "twenty", "one hundred and three", "one thousand", "one thousand two hundred", "eighth thousand seven hundred and fifty seven"); for my $cardinal (@examples) { my $ordinal = ordinalise($cardinal); print "$ordinal\n"; }; sub ordinalise { my $str = shift; my @arr = split " ", $str; my $word = pop @arr; my %ord = ("one" => "first", "two" => "second", "three" => "third", "four" => "fourth", "five" => "fifth", "six" => "sixth", "seven" => "seventh", "eight" => "eighth", "nine" => "ninth", "ten" => "tenth", "eleven" => "eleventh", "twelve" => "twelfth"); { $word =~ s/ty$/tieth/ and next; $word = $ord{$word} and next if defined $ord{$word}; $word .= "th"; } push @arr, $word; return join(" ", @arr); };

Nuance

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://28989]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2022-01-24 16:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?