Erm... this may be a bit late, but I just banged this together:

#!/usr/bin/perl -w use strict; my @ten_factors = (['zilch', 'one', 'two', 'three', 'four', 'five', 's +ix', 'seven', 'eight', 'nine'], ['ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety'], 'thousand', 'million', 'billion', 'trillion', 'quadrillion', 'quintillion', 'sextillion', 'septillion', 'octillion'); sub num2word { my $num = shift;; chomp($num); die "NaN\," if($num !~ /^[0-9]*$/); $num = '0' . $num while(length($num) % 3); my $factor = 0; my $output = ''; while($num) { my @trip = reverse (chop($num), chop($num), chop($num)); my $trip = trip_convert(\@trip); if($factor > 0) { $trip .= ' ' . $ten_factors[$factor+1]; } $output = $trip . ' ' . $output; $factor++; } $output =~ s/zilch [a-z]*//g; return $output; } sub trip_convert { my $trip = shift; my $retval = ''; if($$trip[1] == 1) { $retval = $ten_factors[1][$$trip[2]]; } else { $retval = $ten_factors[0][$$trip[2]]; $retval = $ten_factors[1][$$trip[1]+8] . ' ' . $retval unless($$tr +ip[1] == 0); } $retval = $ten_factors[0][$$trip[0]] . ' hundred ' . $retval; return $retval; }

It isn't exactly the best I've ever written, but it works (more or less).

~Cybercosis

nemo accipere quod non merere


In reply to Re: number 2 text by Cybercosis
in thread number 2 text by Prince99

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.