line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::EN::Numbers::Years; |
2
|
|
|
|
|
|
|
$Lingua::EN::Numbers::Years::VERSION = '1.03'; |
3
|
1
|
|
|
1
|
|
12228
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
5
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Lingua::EN::Numbers 1.01 qw(num2en); |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
159
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter; |
10
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $T = 'thousand'; |
13
|
|
|
|
|
|
|
my $H = 'hundred'; |
14
|
|
|
|
|
|
|
my $Oh = 'oh'; |
15
|
|
|
|
|
|
|
my $Zero = 'zero'; |
16
|
|
|
|
|
|
|
my %DD; |
17
|
|
|
|
|
|
|
my %OhDD; |
18
|
|
|
|
|
|
|
my %D; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @EXPORT = qw(year2en); |
21
|
|
|
|
|
|
|
|
22
|
1
|
50
|
|
1
|
|
1056
|
BEGIN { *DEBUG = sub () {0} unless defined &DEBUG } # setup a DEBUG constant |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
@DD{ '00' .. '09' } = @DD{ '0' .. '9' } = @D{ '0' .. '9' } |
27
|
|
|
|
|
|
|
= @OhDD{ '0' .. '9' } |
28
|
|
|
|
|
|
|
= qw(oh one two three four five six seven eight nine); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
@OhDD{ '00' .. '09' } = map "$Oh $_", @D{ '0' .. '9' }; |
31
|
|
|
|
|
|
|
# Altho "oh oh" presumably is never used |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
for my $num ('10' .. '99') { |
34
|
|
|
|
|
|
|
$OhDD{$num} = $DD{$num} = num2en($num); |
35
|
|
|
|
|
|
|
DEBUG > 1 and print "$num = $DD{$num}\n"; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub year2en ($) { |
41
|
126
|
|
|
126
|
0
|
1749
|
my $y = $_[0]; |
42
|
126
|
100
|
100
|
|
|
823
|
return undef unless defined $y and length $y; |
43
|
124
|
|
|
|
|
275
|
$y =~ s/,//g; |
44
|
124
|
100
|
100
|
|
|
1058
|
if( $y =~ m/\d/ and $y =~ m/^(-?)(\d{1,5})$/s ) { |
45
|
121
|
100
|
|
|
|
415
|
my $neg = $1 ? "negative " : ''; |
46
|
121
|
|
|
|
|
321
|
local $_ = $2; |
47
|
121
|
100
|
|
|
|
306
|
return $Zero if $_ eq '0'; |
48
|
120
|
100
|
|
|
|
442
|
return "$neg$DD{$_}" if $DD{$_}; |
49
|
|
|
|
|
|
|
|
50
|
99
|
100
|
|
|
|
314
|
m/^(..)000$/ and return "$neg$DD{$1} $T"; |
51
|
|
|
|
|
|
|
|
52
|
97
|
100
|
|
|
|
254
|
if( m/^.0...$/ ) { |
53
|
|
|
|
|
|
|
# A family of troublesome cases: things like "60123". |
54
|
|
|
|
|
|
|
# We can't say "sixty one twenty-three" because that sounds |
55
|
|
|
|
|
|
|
# just like sixty-one twenty-three. So we special-case this |
56
|
|
|
|
|
|
|
# whole group. |
57
|
15
|
50
|
|
|
|
60
|
m/^(.0)000$/ and return "$neg$DD{$1} $T"; |
58
|
15
|
100
|
|
|
|
79
|
m/^(.0)00(.)$/ and return "$neg$DD{$1} $T $D{$2}"; |
59
|
12
|
100
|
|
|
|
76
|
m/^(.0)0(..)$/ and return "$neg$DD{$1} $T $DD{$2}"; |
60
|
8
|
100
|
|
|
|
51
|
m/^(.0)(.)00$/ and return "$neg$DD{$1} $T $D{$2} $H"; |
61
|
6
|
50
|
|
|
|
88
|
m/^(.0)(.)(..)$/ and return "$neg$DD{$1} $T $D{$2} $OhDD{$3}"; |
62
|
0
|
|
|
|
|
0
|
DEBUG and print "Falling thru with x0,xxx number $_ !\n"; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
82
|
100
|
|
|
|
197
|
m/^(.)000$/ and return "$neg$DD{$1} $T"; |
66
|
80
|
100
|
|
|
|
201
|
m/^(..)00$/ and return "$neg$DD{$1} $H"; |
67
|
78
|
100
|
|
|
|
200
|
m/^(.)00$/ and return "$neg$DD{$1} $H"; |
68
|
|
|
|
|
|
|
|
69
|
75
|
100
|
|
|
|
179
|
m/^(..)00(.)$/ and return "$neg$DD{$1} $Oh $Oh $DD{$2}"; |
70
|
74
|
100
|
|
|
|
272
|
m/^(..)0(..)$/ and return "$neg$DD{$1} $Oh $DD{$2}"; |
71
|
|
|
|
|
|
|
|
72
|
68
|
100
|
|
|
|
173
|
m/^(.)00(.)$/ and return "$neg$DD{$1} $T $DD{$2}"; |
73
|
|
|
|
|
|
|
#m/^(..)00(.)$/ and return "$neg$DD{$1} $T $DD{$2}"; |
74
|
|
|
|
|
|
|
|
75
|
65
|
100
|
|
|
|
459
|
m/^(..)(.)(..)$/ and return "$neg$OhDD{$1} $D{$2} $OhDD{$3}"; |
76
|
34
|
100
|
|
|
|
207
|
m/^(..)(..)$/ and return "$neg$OhDD{$1} $OhDD{$2}"; |
77
|
13
|
50
|
|
|
|
117
|
m/^(.)(..)$/ and return "$neg$OhDD{$1} $OhDD{$2}"; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Else fallthru: |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
3
|
|
|
|
|
7
|
if(DEBUG) { |
83
|
|
|
|
|
|
|
my $x = num2en($y); |
84
|
|
|
|
|
|
|
print "Using superclass to return numerification \"$x\".\n"; |
85
|
|
|
|
|
|
|
return $x; |
86
|
|
|
|
|
|
|
} else { |
87
|
3
|
|
|
|
|
15
|
return num2en($y); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
#-------------------------------------------------------------------------- |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
__END__ |