in reply to Swap foo and bar in text?

I don't know how it benchmarks, and would need to be convinced that it matters. ;) However, here is another way to do it.

my %swaps = ( foo => 'bar', bar => 'foo' ); $str =~ s/(foo|bar)/$swaps{$1}/g

Dave

Replies are listed 'Best First'.
Re^2: Swap foo and bar in text?
by Cody Fendant (Hermit) on Apr 19, 2012 at 03:52 UTC
    It benchmarks marginally better than the "percentage" method but still way slower than the "evaluated right hand side" method.