Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Number to Speech

by Kozz (Friar)
on Aug 22, 2000 at 09:13 UTC ( #28975=note: print w/ replies, xml ) Need Help??


in reply to Number to Speech

You want the Number::Spell module.


Comment on Re: Number to Speech
RE: Re: Number to Speech
by BlaisePascal (Monk) on Aug 22, 2000 at 12:17 UTC
    Number::Spell looks like a good module for this sort of thing. But do you know of any modules that will handle ordinals? Number::Spell spells out cardinals.

    (For the numerically impaired... cardinals count items (as in "one, two, three"), ordinals order items (as in "first, second, third"). You can tell cardinals by their red robes...)

    UPDATE: Not that I'm complaining, but... I just noticed that this comment has a fairly decent reputation, higher than most of my comments, and equal to what I feel is a deserving comment posted on another thread Re: Search for dupe && append char if found.

    This comment was a smart-assed, throwaway comment (or at least, I intended it to be). Why is it so highly rated?

    I'm not trolling for votes, just curious.

      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
Node Status?
node history
Node Type: note [id://28975]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2014-11-28 03:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (192 votes), past polls