| 1 | |||||||||||||||||||||||||||||
| 2 | 1 | require 5; | |||||||||||||||||||||||||||
| 3 | package Number::Latin; | ||||||||||||||||||||||||||||
| 4 | 1 | $VERSION = '1.01'; # Time-stamp: "2001-02-22 16:43:53 MST" | |||||||||||||||||||||||||||
| 5 | 1 | @ISA = ('Exporter'); | |||||||||||||||||||||||||||
| 6 | 1 | @EXPORT = ('int2latin', 'int2Latin', 'int2LATIN', 'latin2int'); | |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use integer; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 12 | 60 | ▶ | sub int2latin ($) { | ||||||||||||||||||||||||||
|
Subroutine
int2latin: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 13 | 60 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 14 | 60 | ▶ | return '0' if $_[0] == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 15 | 60 | ▶ | return '-' . _i2l( abs int $_[0] ) if $_[0] <= -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 30 | return _i2l( int $_[0] ); | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 2 | ▶ | sub int2Latin ($) { | ||||||||||||||||||||||||||
|
Subroutine
int2Latin: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 20 | # just the above plus ucfirst | ||||||||||||||||||||||||||||
| 21 | 2 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | return '0' if $_[0] == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 2 | ▶ | return '-' . ucfirst(_i2l( abs int $_[0] )) if $_[0] <= -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 1 | return ucfirst(_i2l( int $_[0] )); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 2 | ▶ | sub int2LATIN ($) { | ||||||||||||||||||||||||||
|
Subroutine
int2LATIN: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||
| 28 | # just the above plus uc | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | 2 | ▶ | return '0' if $_[0] == 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 2 | ▶ | return '-' . uc(_i2l( abs int $_[0] )) if $_[0] <= -1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | 1 | return uc(_i2l( int $_[0] )); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||
| 36 | 1 | my @alpha = ('a' .. 'z'); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 208 | ▶ | sub _i2l { # the real work | ||||||||||||||||||||||||||
|
Subroutine
_i2l: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 39 | 208 | ▶ | my $int = shift(@_) || return ""; | ||||||||||||||||||||||||||
|
Condition100%2/2
shift @_ || (return '')
MC/DC100%1/1
shift @_ || (return '')
shift @_
Truth table100%2/2
A
A= shift @_
| |||||||||||||||||||||||||||||
| 40 | 144 | _i2l(int (($int - 1) / 26)) . $alpha[$int % 26 - 1]; # yes, recursive | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 45 | 1 | sub latin2int ($); | |||||||||||||||||||||||||||
| 46 | 96 | ▶ | sub latin2int ($) { | ||||||||||||||||||||||||||
|
Subroutine
latin2int: called CC=6 SCAR=19.1
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 96 | ▶ | return undef unless defined $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 96 | ▶ | return 0 if $_[0] eq '0' or $_[0] =~ m/^0+$/s; # special case | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$_[0] eq 0 or $_[0] =~ /^0+$/s
MC/DC0%0/2
$_[0] eq 0 or $_[0] =~ /^0+$/s
$_[0] eq 0
$_[0] =~ /^0+$/s
Truth table33%1/3
A or B
A= $_[0] eq 0B= $_[0] =~ /^0+$/s
| |||||||||||||||||||||||||||||
| 49 | 96 | my $in = $_[0]; | |||||||||||||||||||||||||||
| 50 | 96 | ▶ | return scalar(-latin2int($1)) if $in =~ m<^-([a-zA-Z]+)$>s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 64 | ▶ | return undef unless $_[0] =~ m<^[a-zA-Z]+$>s; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 64 | $in =~ tr/A-Z/a-z/; | |||||||||||||||||||||||||||
| 53 | 64 | _l2i($in); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # use Number::Latin; print ">\n"; print latin2int('aaa'), "\n"; | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 144 | ▶ | sub _l2i { # the real work. DESTRUCTIVE to $_[0] | ||||||||||||||||||||||||||
|
Subroutine
_l2i: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 59 | #print "<$_[0]> => "; | ||||||||||||||||||||||||||||
| 60 | 144 | my $sval = ord( | |||||||||||||||||||||||||||
| 61 | # my $x = | ||||||||||||||||||||||||||||
| 62 | chop($_[0]) | ||||||||||||||||||||||||||||
| 63 | ) - ord('a') + 1; | ||||||||||||||||||||||||||||
| 64 | #print "sval: $x=>$sval leaving <$_[0]>\n"; | ||||||||||||||||||||||||||||
| 65 | 144 | ▶ | (length $_[0]) ? ($sval + 26 * _l2i($_[0])) : $sval; # yes, recursive | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | #--------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 69 | 1 | 1; | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||||||||||