Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^3: string replacement

by Eily (Parson)
on Sep 12, 2017 at 20:44 UTC ( #1199232=note: print w/replies, xml ) Need Help??

in reply to Re^2: string replacement
in thread string replacement

You're right about putting the longest strings first, if one searched string can be the start of another. That would be my $pattern = join "|", map quotemeta, sort {length $b <=> length $a} keys %replacements;.

With a single substitution operator you don't have to look for the presence of a searched string inside a replacement, because perl will only keep searching after the replaced item, so you can't replace part of a replacement.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1199232]
and the rats come out to play...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2018-01-19 00:34 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (215 votes). Check out past polls.