in reply to Re: Re: Converting ascii to numbers (unpack)
in thread Converting ascii to numbers
use Benchmark 'cmpthese'; use strict; use warnings; my $big; $big .= join '',map chr, 0..255 for 0..255; print length($big), " characters.\n"; sub subst { my $tmp; ($tmp=$big) =~ s/(.)/ord($1).' '/seg; $tmp } sub unpac { my $tmp; $tmp = join ' ', unpack 'C*', $big; $tmp } print length(subst()), " characters in ascii numbers.\n"; print "whoops!\n" if subst() ne unpac().' '; cmpthese( -10, { subst => \&subst, unpac => \&unpac });
|
|---|