$count;
}
+# _num_to_alpha - Returns a string of letters representing a positive integer.
+# Arguments :
+# number to convert
+
+# returns undef if the number is negative
+
+# _num_to_alpha( 0) eq 'A';
+# _num_to_alpha( 1) eq 'B';
+# _num_to_alpha(25) eq 'Z';
+# _num_to_alpha(26) eq 'AA';
+# _num_to_alpha(27) eq 'AB';
+
my @letters = qw(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z);
+# Avoid ++ -- ranges split negative numbers
+sub _num_to_alpha{
+ my($num) = @_;
+ return unless $num >= 0;
+ my $alpha = '';
+ while( 1 ){
+ $alpha = $letters[ $num % 26 ] . $alpha;
+ $num = int( $num / 26 );
+ last if $num == 0;
+ $num = $num - 1;
+ }
+ return $alpha;
+}
+
my %tmpfiles;
END { unlink_all keys %tmpfiles }
--- /dev/null
+#!./perl
+
+BEGIN {
+ chdir 't' if -d 't';
+ @INC = '../lib';
+ require './test.pl';
+}
+
+is( _num_to_alpha(-1), undef);
+is( _num_to_alpha( 0), 'A');
+is( _num_to_alpha( 1), 'B');
+
+is( _num_to_alpha(26 - 1), 'Z');
+is( _num_to_alpha(26 ), 'AA');
+is( _num_to_alpha(26 + 1), 'AB');
+
+is( _num_to_alpha(26 + 26 - 2), 'AY');
+is( _num_to_alpha(26 + 26 - 1), 'AZ');
+is( _num_to_alpha(26 + 26 ), 'BA');
+is( _num_to_alpha(26 + 26 + 1), 'BB');
+
+is( _num_to_alpha(26 ** 2 - 1), 'YZ');
+is( _num_to_alpha(26 ** 2 ), 'ZA');
+is( _num_to_alpha(26 ** 2 + 1), 'ZB');
+
+is( _num_to_alpha(26 ** 2 + 26 - 1), 'ZZ');
+is( _num_to_alpha(26 ** 2 + 26 ), 'AAA');
+is( _num_to_alpha(26 ** 2 + 26 + 1), 'AAB');
+
+is( _num_to_alpha(26 ** 3 + 26 ** 2 + 26 - 1 ), 'ZZZ');
+is( _num_to_alpha(26 ** 3 + 26 ** 2 + 26 ), 'AAAA');
+is( _num_to_alpha(26 ** 3 + 26 ** 2 + 26 + 1 ), 'AAAB');
+
+done_testing();