| 1 | package Number::Spell; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | @ISA = qw(Exporter AutoLoader); | |||||||||||||||||||||||||||
| 9 | # Items to export into callers namespace by default. Note: do not export | ||||||||||||||||||||||||||||
| 10 | # names by default without a very good reason. Use EXPORT_OK instead. | ||||||||||||||||||||||||||||
| 11 | # Do not simply export all your public functions/methods/constants. | ||||||||||||||||||||||||||||
| 12 | 1 | @EXPORT = qw( | |||||||||||||||||||||||||||
| 13 | spell_number | ||||||||||||||||||||||||||||
| 14 | ); | ||||||||||||||||||||||||||||
| 15 | 1 | $VERSION = '0.04'; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Preloaded methods go here. | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 1 | my %expo=( | |||||||||||||||||||||||||||
| 22 | 0 => '', | ||||||||||||||||||||||||||||
| 23 | 1 => 'thousand', | ||||||||||||||||||||||||||||
| 24 | 2 => 'million', | ||||||||||||||||||||||||||||
| 25 | 3 => 'billion', | ||||||||||||||||||||||||||||
| 26 | 4 => 'trillion', | ||||||||||||||||||||||||||||
| 27 | 5 => 'quadrillion', | ||||||||||||||||||||||||||||
| 28 | 6 => 'quintillion', | ||||||||||||||||||||||||||||
| 29 | 7 => 'sextillion', | ||||||||||||||||||||||||||||
| 30 | 8 => 'septillion', | ||||||||||||||||||||||||||||
| 31 | 9 => 'octillion', | ||||||||||||||||||||||||||||
| 32 | 10 => 'nonillion', | ||||||||||||||||||||||||||||
| 33 | 11 => 'decillion', | ||||||||||||||||||||||||||||
| 34 | 12 => 'undecillion', | ||||||||||||||||||||||||||||
| 35 | 13 => 'duodecillion', | ||||||||||||||||||||||||||||
| 36 | 14 => 'tredecillion', | ||||||||||||||||||||||||||||
| 37 | 15 => 'quattuordecillion', | ||||||||||||||||||||||||||||
| 38 | 16 => 'quindecillion', | ||||||||||||||||||||||||||||
| 39 | 17 => 'sexdecillion', | ||||||||||||||||||||||||||||
| 40 | 18 => 'septendecillion', | ||||||||||||||||||||||||||||
| 41 | 19 => 'octodecillion', | ||||||||||||||||||||||||||||
| 42 | 20 => 'novemdecillion', | ||||||||||||||||||||||||||||
| 43 | 21 => 'vigintillion', | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | my %digit=( | |||||||||||||||||||||||||||
| 48 | 0 => '', | ||||||||||||||||||||||||||||
| 49 | 1 => 'one', | ||||||||||||||||||||||||||||
| 50 | 2 => 'two', | ||||||||||||||||||||||||||||
| 51 | 3 => 'three', | ||||||||||||||||||||||||||||
| 52 | 4 => 'four', | ||||||||||||||||||||||||||||
| 53 | 5 => 'five', | ||||||||||||||||||||||||||||
| 54 | 6 => 'six', | ||||||||||||||||||||||||||||
| 55 | 7 => 'seven', | ||||||||||||||||||||||||||||
| 56 | 8 => 'eight', | ||||||||||||||||||||||||||||
| 57 | 9 => 'nine', | ||||||||||||||||||||||||||||
| 58 | 10 => 'ten', | ||||||||||||||||||||||||||||
| 59 | 11 => 'eleven', | ||||||||||||||||||||||||||||
| 60 | 12 => 'twelve', | ||||||||||||||||||||||||||||
| 61 | 13 => 'thirteen', | ||||||||||||||||||||||||||||
| 62 | 14 => 'fourteen', | ||||||||||||||||||||||||||||
| 63 | 15 => 'fifteen', | ||||||||||||||||||||||||||||
| 64 | 16 => 'sixteen', | ||||||||||||||||||||||||||||
| 65 | 17 => 'seventeen', | ||||||||||||||||||||||||||||
| 66 | 18 => 'eighteen', | ||||||||||||||||||||||||||||
| 67 | 19 => 'nineteen', | ||||||||||||||||||||||||||||
| 68 | '2*' => 'twenty', | ||||||||||||||||||||||||||||
| 69 | '3*' => 'thirty', | ||||||||||||||||||||||||||||
| 70 | '4*' => 'forty', | ||||||||||||||||||||||||||||
| 71 | '5*' => 'fifty', | ||||||||||||||||||||||||||||
| 72 | '6*' => 'sixty', | ||||||||||||||||||||||||||||
| 73 | '7*' => 'seventy', | ||||||||||||||||||||||||||||
| 74 | '8*' => 'eighty', | ||||||||||||||||||||||||||||
| 75 | '9*' => 'ninety', | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 10 | ▶ | sub spell_number{ | ||||||||||||||||||||||||||
|
Subroutine
spell_number: called CC=25 SCAR=47.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 79 | 10 | my $data=shift; | |||||||||||||||||||||||||||
| 80 | 10 | my %opts=@_; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 10 | ▶ | if($data=~/(\-?)\s*(\d+)/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 7 | my ($s,$d)=($1,$2); | |||||||||||||||||||||||||||
| 85 | 7 | ▶ | if($d == 0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 86 | 0 | return "zero"; | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | 7 | my $ret=''; | |||||||||||||||||||||||||||
| 89 | 7 | ▶ | if($s eq '-'){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | 0 | $ret='negative '; | |||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||
| 92 | 7 | my $l=length($d); | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 7 | ▶ | if(defined($opts{Format})&&($opts{Format} eq "eu")){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"Format"} and $opts{"Format"} eq "eu"
MC/DC0%0/2
defined $opts{"Format"} and $opts{"Format"} eq "eu"
defined $opts{"Format"}
$opts{"Format"} eq "eu"
Truth table33%1/3
A and B
A= defined $opts{"Format"}B= $opts{"Format"} eq "eu"
| |||||||||||||||||||||||||||||
| 95 | #European formatting | ||||||||||||||||||||||||||||
| 96 | 0 | my $c=1; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | while($l>0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | my $o=$l-6; | |||||||||||||||||||||||||||
| 99 | 0 | my $len=6; | |||||||||||||||||||||||||||
| 100 | 0 | ▶ | if($o<0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | 0 | $len=$len+$o; | |||||||||||||||||||||||||||
| 102 | 0 | $o=0; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | 0 | my $ss=substr $d,$o,$len; | |||||||||||||||||||||||||||
| 105 | 0 | ▶ | while(length($ss)<6){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | $ss='0'.$ss; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | my ($hun1,$tn1,$dig1,$hun2,$tn2,$dig2)=unpack("A1A1A1A1A1A",$ss); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | my $sp=''; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | if($hun1!=0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | 0 | $sp.=$digit{$hun1}." hundred "; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | 0 | ▶ | if($tn1==0){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 116 | 0 | $sp.=" ".$digit{$dig1}." "; | |||||||||||||||||||||||||||
| 117 | }elsif($tn1==1){ | ||||||||||||||||||||||||||||
| 118 | 0 | $sp.=" ".$digit{$tn1.$dig1}." "; | |||||||||||||||||||||||||||
| 119 | }else{ | ||||||||||||||||||||||||||||
| 120 | 0 | $sp.=" ".$digit{$tn1."*"}." ".$digit{$dig1}." "; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | if($sp!~/^\s*$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 0 | $sp.=" thousand "; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if($hun2!=0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | $sp.=$digit{$hun2}." hundred "; | |||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | 0 | ▶ | if($tn2==0){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 131 | 0 | $sp.=" ".$digit{$dig2}." "; | |||||||||||||||||||||||||||
| 132 | }elsif($tn2==1){ | ||||||||||||||||||||||||||||
| 133 | 0 | $sp.=" ".$digit{$tn2.$dig2}." "; | |||||||||||||||||||||||||||
| 134 | }else{ | ||||||||||||||||||||||||||||
| 135 | 0 | $sp.=" ".$digit{$tn2."*"}." ".$digit{$dig2}." "; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 0 | ▶ | if($c==1){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if($sp!~/^\s*$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | 0 | $ret=$sp; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | }else{ | ||||||||||||||||||||||||||||
| 143 | 0 | $ret=$sp.' '.$expo{$c}.' '.$ret; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 0 | $l-=6; | |||||||||||||||||||||||||||
| 146 | 0 | $c++; | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | }else{ | ||||||||||||||||||||||||||||
| 150 | #American formatting | ||||||||||||||||||||||||||||
| 151 | 7 | my $c=0; | |||||||||||||||||||||||||||
| 152 | 7 | ▶ | while($l>0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 14 | my $o=$l-3; | |||||||||||||||||||||||||||
| 154 | 14 | my $len=3; | |||||||||||||||||||||||||||
| 155 | 14 | ▶ | if($o<0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 156 | 6 | $len=$len+$o; | |||||||||||||||||||||||||||
| 157 | 6 | $o=0; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | 14 | my $ss=substr $d,$o,$len; | |||||||||||||||||||||||||||
| 160 | 14 | my $sp=''; | |||||||||||||||||||||||||||
| 161 | 14 | ▶ | while(length($ss)<3){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 9 | $ss='0'.$ss; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | 14 | my ($hun,$tn,$dig)=unpack("A1A1A1",$ss); | |||||||||||||||||||||||||||
| 165 | 14 | ▶ | if($hun!=0){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | 3 | $sp.=$digit{$hun}." hundred "; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | 14 | ▶ | if($tn==0){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 169 | 8 | $sp.=" ".$digit{$dig}." "; | |||||||||||||||||||||||||||
| 170 | }elsif($tn==1){ | ||||||||||||||||||||||||||||
| 171 | 1 | $sp.=" ".$digit{$tn.$dig}." "; | |||||||||||||||||||||||||||
| 172 | }else{ | ||||||||||||||||||||||||||||
| 173 | 5 | $sp.=" ".$digit{$tn."*"}." ".$digit{$dig}." "; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | 14 | ▶ | if($sp!~/^\s*$/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | 9 | $ret=$sp.' '.$expo{$c}.' '.$ret; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | 14 | $l-=3; | |||||||||||||||||||||||||||
| 179 | 14 | $c++; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 7 | $ret=~s/\s\s+/ /g; | |||||||||||||||||||||||||||
| 185 | 7 | $ret=~s/^\s//g; | |||||||||||||||||||||||||||
| 186 | 7 | $ret=~s/\s$//g; | |||||||||||||||||||||||||||
| 187 | 7 | return $ret; | |||||||||||||||||||||||||||
| 188 | }else{ | ||||||||||||||||||||||||||||
| 189 | 3 | return ""; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 1 | 1; | |||||||||||||||||||||||||||
| 198 | __END__ | ||||||||||||||||||||||||||||