line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Lingua::PT::Ords2Nums;
|
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
140498
|
use 5.006;
|
|
3
|
|
|
|
|
17
|
|
4
|
3
|
|
|
3
|
|
14
|
use strict;
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
79
|
|
5
|
3
|
|
|
3
|
|
17
|
use warnings;
|
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
110
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1406
|
use Lingua::PT::Words2Nums qw/word2num/;
|
|
3
|
|
|
|
|
2774
|
|
|
3
|
|
|
|
|
1081
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
require Exporter;
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter);
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw(
|
14
|
|
|
|
|
|
|
ord2num
|
15
|
|
|
|
|
|
|
) ] );
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw(
|
20
|
|
|
|
|
|
|
);
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.08';
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my %values = (
|
25
|
|
|
|
|
|
|
'bilionésimo' => 1000000000,
|
26
|
|
|
|
|
|
|
'milionésimo' => 1000000,
|
27
|
|
|
|
|
|
|
'milésimo' => 1000,
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
'nongentésimo' => 900,
|
30
|
|
|
|
|
|
|
'octigentésimo' => 800,
|
31
|
|
|
|
|
|
|
'septigentésimo' => 700,
|
32
|
|
|
|
|
|
|
'seiscentésimo' => 600,
|
33
|
|
|
|
|
|
|
'quingentésimo' => 500,
|
34
|
|
|
|
|
|
|
'quadrigentésimo' => 400,
|
35
|
|
|
|
|
|
|
'tricentésimo' => 300,
|
36
|
|
|
|
|
|
|
'ducentésimo' => 200,
|
37
|
|
|
|
|
|
|
'centésimo' => 100,
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
'nonagésimo' => 90,
|
40
|
|
|
|
|
|
|
'octogésimo' => 80,
|
41
|
|
|
|
|
|
|
'septuagésimo' => 70,
|
42
|
|
|
|
|
|
|
'sexagésimo' => 60,
|
43
|
|
|
|
|
|
|
'quinquagésimo' => 50,
|
44
|
|
|
|
|
|
|
'quadragésimo' => 40,
|
45
|
|
|
|
|
|
|
'trigésimo' => 30,
|
46
|
|
|
|
|
|
|
'vigésimo' => 20,
|
47
|
|
|
|
|
|
|
'décimo' => 10,
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
'nono' => 9,
|
50
|
|
|
|
|
|
|
'oitavo' => 8,
|
51
|
|
|
|
|
|
|
'sétimo' => 7,
|
52
|
|
|
|
|
|
|
'sexto' => 6,
|
53
|
|
|
|
|
|
|
'quinto' => 5,
|
54
|
|
|
|
|
|
|
'quarto' => 4,
|
55
|
|
|
|
|
|
|
'terceiro' => 3,
|
56
|
|
|
|
|
|
|
'segundo' => 2,
|
57
|
|
|
|
|
|
|
'primeiro' => 1,
|
58
|
|
|
|
|
|
|
);
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Order of application is important, but hashes are unsorted.
|
61
|
|
|
|
|
|
|
# So we need to store the order of the keys in an array.
|
62
|
|
|
|
|
|
|
my @key_sorted_order = (
|
63
|
|
|
|
|
|
|
'bilionésimo',# => 1000000000,
|
64
|
|
|
|
|
|
|
'milionésimo',# => 1000000,
|
65
|
|
|
|
|
|
|
'milésimo',# => 1000,
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
'nongentésimo',# => 900,
|
68
|
|
|
|
|
|
|
'octigentésimo',# => 800,
|
69
|
|
|
|
|
|
|
'septigentésimo',# => 700,
|
70
|
|
|
|
|
|
|
'seiscentésimo',# => 600,
|
71
|
|
|
|
|
|
|
'quingentésimo',# => 500,
|
72
|
|
|
|
|
|
|
'quadrigentésimo',# => 400,
|
73
|
|
|
|
|
|
|
'tricentésimo',# => 300,
|
74
|
|
|
|
|
|
|
'ducentésimo',# => 200,
|
75
|
|
|
|
|
|
|
'centésimo',# => 100,
|
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
'nonagésimo',# => 90,
|
78
|
|
|
|
|
|
|
'octogésimo',# => 80,
|
79
|
|
|
|
|
|
|
'septuagésimo',# => 70,
|
80
|
|
|
|
|
|
|
'sexagésimo',# => 60,
|
81
|
|
|
|
|
|
|
'quinquagésimo',# => 50,
|
82
|
|
|
|
|
|
|
'quadragésimo',# => 40,
|
83
|
|
|
|
|
|
|
'trigésimo',# => 30,
|
84
|
|
|
|
|
|
|
'vigésimo',# => 20,
|
85
|
|
|
|
|
|
|
'décimo',# => 10,
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
'nono',# => 9,
|
88
|
|
|
|
|
|
|
'oitavo',# => 8,
|
89
|
|
|
|
|
|
|
'sétimo',# => 7,
|
90
|
|
|
|
|
|
|
'sexto',# => 6,
|
91
|
|
|
|
|
|
|
'quinto',# => 5,
|
92
|
|
|
|
|
|
|
'quarto',# => 4,
|
93
|
|
|
|
|
|
|
'terceiro',# => 3,
|
94
|
|
|
|
|
|
|
'segundo',# => 2,
|
95
|
|
|
|
|
|
|
'primeiro',# => 1,
|
96
|
|
|
|
|
|
|
);
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 NAME
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=encoding latin1
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Lingua::PT::Ords2Nums - Converts Portuguese ordinals to numbers
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
use Lingua::PT::Ords2Nums qw/ord2num/;
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
$num = word2num('décimo primeiro') # 11
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Converts Portuguese ordinals to numbers. Works up to 999.999.999.999
|
114
|
|
|
|
|
|
|
('novecentos e noventa e nove bilionésimos novecentos e noventa e nove
|
115
|
|
|
|
|
|
|
milionésimos novecentos e noventa e nove milésimos nongentésimo nonagésimo
|
116
|
|
|
|
|
|
|
nono').
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head2 ord2num
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Turns an ordinal number into a regular number (decimal).
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
$num = word2num('segundo')
|
125
|
|
|
|
|
|
|
# $num now holds 2
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=cut
|
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub ord2num {
|
130
|
50
|
|
100
|
50
|
1
|
324
|
$_ = shift || return undef;
|
131
|
49
|
|
|
|
|
69
|
my $result = 0;
|
132
|
|
|
|
|
|
|
|
133
|
49
|
|
|
|
|
137
|
s/(.*)bilionésimos/$result += (word2num($1) * 1000000000)/e;
|
|
8
|
|
|
|
|
24
|
|
134
|
49
|
|
|
|
|
2171
|
s/(.*)milionésimos/$result += (word2num($1) * 1000000)/e;
|
|
8
|
|
|
|
|
23
|
|
135
|
49
|
|
|
|
|
2198
|
s/(.*)milésimos/$result += (word2num($1) * 1000)/e;
|
|
14
|
|
|
|
|
42
|
|
136
|
|
|
|
|
|
|
|
137
|
49
|
|
|
|
|
3762
|
for my $value ( @key_sorted_order ) {
|
138
|
1470
|
|
|
|
|
7674
|
s/$value/$result += $values{$value}/e;
|
|
78
|
|
|
|
|
252
|
|
139
|
|
|
|
|
|
|
}
|
140
|
|
|
|
|
|
|
|
141
|
49
|
|
|
|
|
189
|
$result;
|
142
|
|
|
|
|
|
|
}
|
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1;
|
145
|
|
|
|
|
|
|
__END__
|