in reply to Re: Regular expression question
in thread Regular expression question

s/(.)/$hash{$1}/eg
Will end up removing all chars in the string that are not specifically listed in the hash.

I also believe that tr/// is always faster than s///.

#!/usr/local/bin/perl use strict; use Benchmark; timethese( 1000000, { trchange => \&trchange, schange => \&schange, }); sub trchange { my $s = q{123 abc def a b a b a b}; $s =~ tr/a/A/; } sub schange { my $s = q{123 abc def a b a b a b}; $s =~ s/a/A/g; } # Benchmark: timing 1000000 iterations of schange, trchange... # schange: 21 wallclock secs (21.39 usr + 0.01 sys = 21.40 CPU) @ 4 +6728.97/s (n=1000000) # trchange: 7 wallclock secs ( 6.41 usr + 0.01 sys = 6.42 CPU) @ 1 +55763.24/s (n=1000000)
Wonko