I would like to do something like the following in perl:
@digits = ("1", "2", ..., "a", ... "z", ... ); ## a list of characters
$num = 1033;
convert_to_base($num, @digits);
Now, $num
will be converted to a string with the digits being used are from digits (so the base is $#digits + 1
).
It can be done by iterating on $num
, taking the modulo of $num with respect to $#digits
and then dividing until 0 is reached, but I was wondering if there is any built-in function that does that in perl (or alternatively a fast function that would do it in perl).