http://qs1969.pair.com?node_id=1197808


in reply to Math::Base - arithmetics with baseX integers (updated)

This is a neat idea, but encode spins forever when $num is negative and returns an empty string when it's zero. You could do this:
my $val = abs($num); do { push @ret, $chars[$val % $base]; $val = int($val / $base); } while $val; push @ret, '-' if $num < 0;
But '-' is in the @chars array.