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

In reply to Re^3: Get Excel column name for given decimal number by Tux
in thread Get Excel column name for given decimal number by Akshit

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.