in reply to Base20 Blues

my @digits; while ($num > 0) { unshift @digits, $num % 20; $num = int($num / 20); } @digits = 0 if !@digits;

Or you can use an existing module, like Convert::BaseN. (I have no experience with it; I just picked one pretty arbitrarily.)

Replies are listed 'Best First'.
Re^2: Base20 Blues
by chrestomanci (Priest) on Jan 10, 2011 at 09:11 UTC

    Sorry, Convert::BaseN Won't work, as it only supports number bases that are powers of two. From the POD docs:

    Convert::BaseN - encoding and decoding of base{2,4,8,16,32,64} strings

    Mind you, I would have made the same mistake. I had already given you a ++ before I checked the pod for that module.

Re^2: Base20 Blues
by Anonymous Monk on Jan 10, 2011 at 13:40 UTC
    Thanks for your help to all. I really like the simplicity of ikegami's reply, but while it gives the answers, how would I make it so that it returns something when the result is zero, because the maya had a zero place holder. The others are also great, and I will learn from them; I just would rather not have to use a cpan module for such a simple task, and I need the results by number so I can output a symbol gif for each. Again, thanks to you pros.

      how would I make it so that it returns something when the result is zero

      It currently puts 0 in @digits. Adjust the last line as desired.

      @digits = 0 if !@digits;

      I just would rather not have to use a cpan module for such a simple task

      Well, it was complex enough that you wanted help with it. I'm also convinced mine can give the wrong result due to floating point error.

      my @digits; do { unshift @digits, $num % 20; $num = ( $num - ( $num % 20 ) ) / 20; } while $num > 0;