SXG.pm

# Simplest conversion from PHP to Perl.
# Based on PHP code from http://tantek.pbworks.com/w/page/19402946/NewBase60
# PHP code by Tantek Çelik http://tantek.com

sub num_to_sxg {
my ($n) = @_;
my $s = "";
my @m = split//,"0123456789ABCDEFGHJKLMNPQRSTUVWXYZ_abcdefghijkmnopqrstuvwxyz";
if (!$n) { return 0; }
while ($n>0) {
my $d = $n % 60;
$s = $m[$d].$s;
$n = ($n-$d)/60;
}
return $s;
}

sub num_to_sxgf {
my ($n, $f) = @_;
my $s = num_to_sxg($n);
if (!$f) {
$f=1;
}
$f -= length($s);
while ($f > 0) {
$s = "0".$s;
--$f;
}
return $s;
}

sub sxg_to_num {
my ($s) = @_;
my $n = 0;
my @s = split//,$s;
my $j = length($s);
for (my $i=0;$i<$j;$i++) {
my $c = ord($s[$i]);
if ($c>=48 && $c<=57) { $c=$c-48; }
elsif ($c>=65 && $c<=72) { $c-=55; }
elsif ($c==73 || $c==108) { $c=1; }
elsif ($c>=74 && $c<=78) { $c-=56; }
elsif ($c==79) { $c=0; }
elsif ($c>=80 && $c<=90) { $c-=57; }
elsif ($c==95) { $c=34; }
elsif ($c>=97 && $c<=107) { $c-=62; }
elsif ($c>=109 && $c<=122) { $c-=63; }
else { $c = 0; }
$n = 60*$n + $c;
}
return $n;
}