Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Swap foo and bar in text?

by davido (Cardinal)
on Apr 18, 2012 at 04:46 UTC ( [id://965618]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://965618]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found