end0tknr's kipple - 新web写経開発

http://d.hatena.ne.jp/end0tknr/ から移転します

Math::BaseCalcで16進数以外の基数変換

31進数で出力する必要があるらしいので...
http://search.cpan.org/perldoc?Math%3A%3ABaseCalc

#!/usr/local/bin/perl
use strict;
use utf8;
use Math::BaseCalc;

main();

sub main {

    my $base_31 = Math::BaseCalc->new(digits=>[0..9,'A'..'U']);
    print $base_31->to_base(0),"\n";
    print $base_31->to_base(1),"\n";
    print $base_31->to_base(10),"\n";
    print $base_31->to_base(31),"\n";
    print $base_31->to_base(32),"\n";
}

実行結果

$ ./foo.pl 
0
1
A
10
11