Take into account that there is a real performance difference between the three methods, which especially shows for high column numbers:
(warning: too few iterations for a reliable count)
Rate getcolname int2LATIN col2label
getcolname 0.119/s -- -100% -100%
int2LATIN 31.4/s 26218% -- -55%
col2label 68.9/s 57742% 120% --
So if this is hot code, don't use johngg's version, however nice his solution is :)
use 5.14.2;
use warnings;
use Benchmark qw( cmpthese );
use Number::Latin qw( int2LATIN );
# johngg: [id://11114715]
sub getColName {
my ($s, $n) = ("A", @_);
while ($n-- > 1) { $s++ }
$s;
} # getColName
# tux: [id://11114673]
sub col2label {
my ($s, $n) = ("", @_);
while ($n) {
use integer;
substr $s, 0, 0, chr (--$n % 26 + ord "A");
$n /= 26;
}
$s;
} # col2label
getColName (10342) eq "OGT" or die "getColName is wrong";
col2label (10342) eq "OGT" or die "col2label is wrong";
int2LATIN (10342) eq "OGT" or die "int2LATIN is wrong";
cmpthese (-4, {
getcolname => sub { getColName ($_) for 1 .. 20000 },
col2label => sub { col2label ($_) for 1 .. 20000 },
int2LATIN => sub { int2LATIN ($_) for 1 .. 20000 },
});
Enjoy, Have FUN! H.Merijn