Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re^3: string replacement

by Eily (Prior)
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2018-07-18 11:05 GMT
Find Nodes?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?

    Results (389 votes). Check out past polls.