| Lingua-PT-Ords2Nums documentation | Contained in the Lingua-PT-Ords2Nums distribution. |
Lingua::PT::Ords2Nums - Converts Portuguese ordinals to numbers
use Lingua::PT::Ords2Nums qw/ord2num/;
$num = word2num('décimo primeiro') # 11
Converts Portuguese ordinals to numbers. Works up to 999.999.999.999 ('novecentos e noventa e nove bilionésimos novecentos e noventa e nove milionésimos novecentos e noventa e nove milésimos nongentésimo nonagésimo nono').
Turns an ordinal number into a regular number (decimal).
$num = word2num('segundo')
# $num now holds 2
Lingua::PT::Words2Nums
More tools for the Portuguese language processing can be found at the Natura project: http://natura.di.uminho.pt
Jose Castro, <cog@cpan.org>
Copyright 2004 Jose Castro, All Rights Reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Lingua-PT-Ords2Nums documentation | Contained in the Lingua-PT-Ords2Nums distribution. |
package Lingua::PT::Ords2Nums; use 5.006; use strict; use warnings; use Lingua::PT::Words2Nums qw/word2num/; require Exporter; our @ISA = qw(Exporter); our %EXPORT_TAGS = ( 'all' => [ qw( ord2num ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.07'; my %values;
BEGIN { %values = ( 'bilionésimo' => 1000000000, 'milionésimo' => 1000000, 'milésimo' => 1000, 'nongentésimo' => 900, 'octigentésimo' => 800, 'septigentésimo' => 700, 'seiscentésimo' => 600, 'quingentésimo' => 500, 'quadrigentésimo' => 400, 'tricentésimo' => 300, 'ducentésimo' => 200, 'centésimo' => 100, 'nonagésimo' => 90, 'octogésimo' => 80, 'septuagésimo' => 70, 'sexagésimo' => 60, 'quinquagésimo' => 50, 'quadragésimo' => 40, 'trigésimo' => 30, 'vigésimo' => 20, 'décimo' => 10, nono => 9, oitavo => 8, 'sétimo' => 7, sexto => 6, quinto => 5, quarto => 4, terceiro => 3, segundo => 2, primeiro => 1, ); }
sub ord2num { $_ = shift || return undef; my $result = 0; s/(.*)bilionésimos/$result += (word2num($1) * 1000000000)/e; s/(.*)milionésimos/$result += (word2num($1) * 1000000)/e; s/(.*)milésimos/$result += (word2num($1) * 1000)/e; for my $value (keys %values) { s/$value/$result += $values{$value}/e; } $result; } 1; __END__