line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Spell; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
614
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
944
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
@EXPORT = qw( |
13
|
|
|
|
|
|
|
spell_number |
14
|
|
|
|
|
|
|
); |
15
|
|
|
|
|
|
|
$VERSION = '0.04'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Preloaded methods go here. |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub spell_number{ |
79
|
10
|
|
|
10
|
0
|
10521
|
my $data=shift; |
80
|
10
|
|
|
|
|
21
|
my %opts=@_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
10
|
100
|
|
|
|
45
|
if($data=~/(\-?)\s*(\d+)/){ |
84
|
7
|
|
|
|
|
19
|
my ($s,$d)=($1,$2); |
85
|
7
|
50
|
|
|
|
21
|
if($d == 0){ |
86
|
0
|
|
|
|
|
0
|
return "zero"; |
87
|
|
|
|
|
|
|
} |
88
|
7
|
|
|
|
|
10
|
my $ret=''; |
89
|
7
|
50
|
|
|
|
13
|
if($s eq '-'){ |
90
|
0
|
|
|
|
|
0
|
$ret='negative '; |
91
|
|
|
|
|
|
|
} |
92
|
7
|
|
|
|
|
11
|
my $l=length($d); |
93
|
|
|
|
|
|
|
|
94
|
7
|
50
|
33
|
|
|
19
|
if(defined($opts{Format})&&($opts{Format} eq "eu")){ |
95
|
|
|
|
|
|
|
#European formatting |
96
|
0
|
|
|
|
|
0
|
my $c=1; |
97
|
0
|
|
|
|
|
0
|
while($l>0){ |
98
|
0
|
|
|
|
|
0
|
my $o=$l-6; |
99
|
0
|
|
|
|
|
0
|
my $len=6; |
100
|
0
|
0
|
|
|
|
0
|
if($o<0){ |
101
|
0
|
|
|
|
|
0
|
$len=$len+$o; |
102
|
0
|
|
|
|
|
0
|
$o=0; |
103
|
|
|
|
|
|
|
} |
104
|
0
|
|
|
|
|
0
|
my $ss=substr $d,$o,$len; |
105
|
0
|
|
|
|
|
0
|
while(length($ss)<6){ |
106
|
0
|
|
|
|
|
0
|
$ss='0'.$ss; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
0
|
my ($hun1,$tn1,$dig1,$hun2,$tn2,$dig2)=unpack("A1A1A1A1A1A",$ss); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
my $sp=''; |
112
|
0
|
0
|
|
|
|
0
|
if($hun1!=0){ |
113
|
0
|
|
|
|
|
0
|
$sp.=$digit{$hun1}." hundred "; |
114
|
|
|
|
|
|
|
} |
115
|
0
|
0
|
|
|
|
0
|
if($tn1==0){ |
|
|
0
|
|
|
|
|
|
116
|
0
|
|
|
|
|
0
|
$sp.=" ".$digit{$dig1}." "; |
117
|
|
|
|
|
|
|
}elsif($tn1==1){ |
118
|
0
|
|
|
|
|
0
|
$sp.=" ".$digit{$tn1.$dig1}." "; |
119
|
|
|
|
|
|
|
}else{ |
120
|
0
|
|
|
|
|
0
|
$sp.=" ".$digit{$tn1."*"}." ".$digit{$dig1}." "; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
0
|
0
|
|
|
|
0
|
if($sp!~/^\s*$/){ |
124
|
0
|
|
|
|
|
0
|
$sp.=" thousand "; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
0
|
0
|
|
|
|
0
|
if($hun2!=0){ |
128
|
0
|
|
|
|
|
0
|
$sp.=$digit{$hun2}." hundred "; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
0
|
|
|
|
0
|
if($tn2==0){ |
|
|
0
|
|
|
|
|
|
131
|
0
|
|
|
|
|
0
|
$sp.=" ".$digit{$dig2}." "; |
132
|
|
|
|
|
|
|
}elsif($tn2==1){ |
133
|
0
|
|
|
|
|
0
|
$sp.=" ".$digit{$tn2.$dig2}." "; |
134
|
|
|
|
|
|
|
}else{ |
135
|
0
|
|
|
|
|
0
|
$sp.=" ".$digit{$tn2."*"}." ".$digit{$dig2}." "; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
0
|
|
|
|
0
|
if($c==1){ |
139
|
0
|
0
|
|
|
|
0
|
if($sp!~/^\s*$/){ |
140
|
0
|
|
|
|
|
0
|
$ret=$sp; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
}else{ |
143
|
0
|
|
|
|
|
0
|
$ret=$sp.' '.$expo{$c}.' '.$ret; |
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
0
|
$l-=6; |
146
|
0
|
|
|
|
|
0
|
$c++; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
}else{ |
150
|
|
|
|
|
|
|
#American formatting |
151
|
7
|
|
|
|
|
9
|
my $c=0; |
152
|
7
|
|
|
|
|
15
|
while($l>0){ |
153
|
14
|
|
|
|
|
16
|
my $o=$l-3; |
154
|
14
|
|
|
|
|
13
|
my $len=3; |
155
|
14
|
100
|
|
|
|
24
|
if($o<0){ |
156
|
6
|
|
|
|
|
6
|
$len=$len+$o; |
157
|
6
|
|
|
|
|
4
|
$o=0; |
158
|
|
|
|
|
|
|
} |
159
|
14
|
|
|
|
|
20
|
my $ss=substr $d,$o,$len; |
160
|
14
|
|
|
|
|
14
|
my $sp=''; |
161
|
14
|
|
|
|
|
26
|
while(length($ss)<3){ |
162
|
9
|
|
|
|
|
20
|
$ss='0'.$ss; |
163
|
|
|
|
|
|
|
} |
164
|
14
|
|
|
|
|
44
|
my ($hun,$tn,$dig)=unpack("A1A1A1",$ss); |
165
|
14
|
100
|
|
|
|
43
|
if($hun!=0){ |
166
|
3
|
|
|
|
|
6
|
$sp.=$digit{$hun}." hundred "; |
167
|
|
|
|
|
|
|
} |
168
|
14
|
100
|
|
|
|
32
|
if($tn==0){ |
|
|
100
|
|
|
|
|
|
169
|
8
|
|
|
|
|
15
|
$sp.=" ".$digit{$dig}." "; |
170
|
|
|
|
|
|
|
}elsif($tn==1){ |
171
|
1
|
|
|
|
|
3
|
$sp.=" ".$digit{$tn.$dig}." "; |
172
|
|
|
|
|
|
|
}else{ |
173
|
5
|
|
|
|
|
17
|
$sp.=" ".$digit{$tn."*"}." ".$digit{$dig}." "; |
174
|
|
|
|
|
|
|
} |
175
|
14
|
100
|
|
|
|
45
|
if($sp!~/^\s*$/){ |
176
|
9
|
|
|
|
|
28
|
$ret=$sp.' '.$expo{$c}.' '.$ret; |
177
|
|
|
|
|
|
|
} |
178
|
14
|
|
|
|
|
16
|
$l-=3; |
179
|
14
|
|
|
|
|
32
|
$c++; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
|
184
|
7
|
|
|
|
|
33
|
$ret=~s/\s\s+/ /g; |
185
|
7
|
|
|
|
|
23
|
$ret=~s/^\s//g; |
186
|
7
|
|
|
|
|
16
|
$ret=~s/\s$//g; |
187
|
7
|
|
|
|
|
24
|
return $ret; |
188
|
|
|
|
|
|
|
}else{ |
189
|
3
|
|
|
|
|
10
|
return ""; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
1; |
198
|
|
|
|
|
|
|
__END__ |