in reply to Opposite of strtol?

sub tobase { my $radix = int($_[0]); (my $num = int($_[1])) =~ y/-/_/; + chomp(my $str = `dc -e${radix}o${num}p`); $str } print tobase(13, 54), "\n"; # outputs 42

Update: fixed the syntax errors, I've no idea how I got them there, sorry.

Replies are listed 'Best First'.
Re^2: Opposite of strtol?
by jettero (Monsignor) on Jun 21, 2009 at 18:57 UTC
    surely there's a way to avoid `dc`

    -Paul