Hi pals,

I'd like to code my own encode function, I have @list of allowed
characters, my input is number, and I'd like to 'convert' number to
characters. Here is script I coded, but I'm sure it could be really
better. This script should work, but there are too much conditions and
isn't so clear as I think it could be:

use strict;
use warnings;

my $a = 123456789; # $a >= 0
my @list = ( 'a' .. 'z', 'A' .. 'Z', 0 .. 9, '-', '_' );

print my $out = reverse(fn($a));

sub fn {
        my $a = shift;
        my $out = shift || '';
        $out .= $list[$a % @list];
        my $b = ($a/@list)-1;
        if ( $b >= @list ) { $out .= fn($b) }
        $out .= $list[$b] if $list[$b] and $b >= 0; 
        return $out;
}
__END__

prints: gv7Zv

So if anyone helps me, how to clear it, I will be glad.

Thanks.

/Brano


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to