Or you could write that as:
use List::Util qw[ max ]; sub encoding { my @characters = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9, '-', '.' ); my $max = max( $_[ 0 ] =~ /\d+/g ); return join ',', map join( '', map $characters[ $_ / 64 ] . $chara +cters[ $_ % 64 ], map $_ / $max * 4095, split /,/ ), split /\|/, $_[ +0 ]; }
Udate: or another way to do it:
sub encoding { my ( $string ) = @_; my @characters = ( 'A' .. 'Z', 'a' .. 'z', 0 .. 9, '-', '.' ); my $max = max( $string =~ /\d+/g ); $string =~ s{ ( \d+ ) }{$characters[ ( $1 / $max * 4095 ) / 64 ]$c +haracters[ ( $1 / $max * 4095 ) % 64 ]}xg; $string =~ tr/,//d; $string =~ tr/|/,/; return $string; }
In reply to Re: Perl and Google Charts extended encoding
by jwkrahn
in thread Perl and Google Charts extended encoding
by PoliceCoP
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |