in reply to Perl and Google Charts extended encoding
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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl and Google Charts extended encoding
by PoliceCoP (Acolyte) on May 07, 2011 at 17:02 UTC |