good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Item Description: Perl extension for spelling out numbers.
Review Synopsis:
CPAN LINK: Number::Spell
CPAN ABSTRACT: Number::Spell provides functionality for spelling out numbers. Currently only integers are supported.
Introduction:
Every so often I get the urge to troll around the CPAN Module Repository to see what is interesting. This module caught my eye as a 'Cool Use for Perl', so I thought I would download it and give it a try.
Functionality:
Number::Spell, upon initial tinkering does what it says spells out integers into english words. I tested it out on some 'smaller' numbers (see demo below) and it seemed to work fine. So... I thought to myself lets see if we can break it, after all the documentation say it can go into the 'vigintillions' Unfortunately, I was successful at breaking it. I hit the ceiling at 100 trillion, after adding one more zero, which would then be one quadrillion, it only returned 'one'.
Demo Code:
Bug(s) Found: Stops working properly after 100 Trillion.#!/usr/bin/perl -w use strict; use Number::Spell; my $string=spell_number(8597); print "$string\n"; ----- Result: eight thousand five hundred ninety seven
With a little more tinkering/experimentation with the demo script I have determined that such a large number will work with the module if you send it as a quoted string.if($data=~/(\-?)\s*(\d+)/){
The ultimate solution would be to fix the regex on line 83 in spell.pm to deal with the exponential format. Unfortunately a regex wizard I am not. So.... I would be inclined to leave that in the hands of the author or someone who knows more of regexes than I do. :)my $string=spell_number('1000000000000000'); #this works my $string=spell_number(1000000000000000); #this doesNOT
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Number::Spell
by blokhead (Monsignor) on Jan 28, 2004 at 14:26 UTC | |
Re: Number::Spell
by halley (Prior) on Feb 05, 2004 at 16:51 UTC |