File Coverage

blib/lib/Spreadsheet/ConvertAA.pm
Criterion Covered Total %
statement 32 32 100.0
branch 4 6 66.6
condition n/a
subroutine 8 8 100.0
pod 0 2 0.0
total 44 48 91.6


line stmt bran cond sub pod time code
1              
2             package Spreadsheet::ConvertAA;
3              
4 1     1   6843 use 5.006;
  1         5  
  1         52  
5 1     1   5 use strict;
  1         3  
  1         39  
6 1     1   15 use warnings;
  1         10  
  1         43  
7 1     1   5 use Carp ;
  1         2  
  1         98  
8              
9             require Exporter;
10 1     1   927 use AutoLoader qw(AUTOLOAD);
  1         1681  
  1         7  
11              
12             our @ISA = qw(Exporter);
13             our %EXPORT_TAGS = ( 'all' => [ qw() ] );
14             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
15             our @EXPORT = qw( FromAA ToAA);
16             our $VERSION = '0.06';
17              
18              
19             #----------------------------------------------------
20              
21             sub ToAA($)
22             {
23 475255     475255 0 3581832 my $c = shift ;
24 475255 50       1163490 confess "Invalid base10 '$c'" if($c =~ /[^0-9]/) ;
25              
26 475255 100       852083 return('@') if $c == 0 ;
27              
28 475254         543607 my $cell = "";
29              
30 475254         820736 while($c)
31             {
32 1     1   1190 use integer;
  1         12  
  1         5  
33 1882010         2316915 substr ($cell, 0, 0) = chr (--$c % 26 + ord "A");
34 1882010         2960661 $c /= 26;
35             }
36              
37 475254         1002416 return($cell) ;
38             }
39              
40             sub FromAA ($)
41             {
42 475255     475255 0 1273073 my $cc = shift ;
43 475255 50       1057598 confess "Invalid baseAA '$cc'" if($cc =~ /[^A-Za-z@]/) ;
44              
45 475255         512084 my $c = 0;
46              
47 475255         1474376 while($cc =~ s/^([A-Z])//)
48             {
49 1882010         6259148 $c = 26 * $c + 1 + ord ($1) - ord ("A");
50             }
51              
52 475255         818701 return($c);
53             }
54              
55             #----------------------------------------------------
56              
57             1;
58             __END__