is still useless because you read to $data only the first string from __DATA__ section :)our $data = <DATA>;
IMHO it is exactly what you wanted to do:)our $data = join "", <DATA>;
The worst thing about tr/// is that it can produce only character-to-character mapping. The best solution aviding this problem I found uses eval at compilation time:
It is only 52 times slower than tr/// :BEGIN { our %rot = ( 'A' => 'N','B' => 'O','C' => 'P','D' => 'Q','E' => 'R','F' => 'S', 'G' => 'T','H' => 'U','I' => 'V','J' => 'W','K' => 'X','L' => 'Y', 'M' => 'Z','N' => 'A','O' => 'B','P' => 'C','Q' => 'D','R' => 'E', 'S' => 'F','T' => 'G','U' => 'H','V' => 'I','W' => 'J','X' => 'K', 'Y' => 'L','Z' => 'M','a' => 'n','b' => 'o','c' => 'p','d' => 'q', 'e' => 'r','f' => 's','g' => 't','h' => 'u','i' => 'v','j' => 'w', 'k' => 'x','l' => 'y','m' => 'z','n' => 'a','o' => 'b','p' => 'c', 'q' => 'd','r' => 'e','s' => 'f','t' => 'g','u' => 'h','v' => 'i', 'w' => 'j','x' => 'k','y' => 'l','z' => 'm', ); my $substs = join "\n", map { " s/$_/$rot{$_}/g;" } keys %rot; eval <<SUB; sub rot13s { local \$_ = shift; $substs; return \$_; } SUB }
Rate table s///g tr table 448/s -- -78% -100% s///g 2026/s 352% -- -98% tr 106383/s 23654% 5152% --
In reply to Re: The indisputable speed of tr///
by Ieronim
in thread The indisputable speed of tr///
by radiantmatrix
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |