No such thing as a small change | |
PerlMonks |
Re: backreference on hashby MidLifeXis (Monsignor) |
on Aug 14, 2015 at 13:24 UTC ( [id://1138580]=note: print w/replies, xml ) | Need Help?? |
Careful about using a hash for this, as the Let's say you have a set of two regexes in your hash: { a => 'b', b => 'c'}. If the 'a' key is used first, you will end up with no 'b' values in your results. OTOH, if the 'b' key is used first, you might (if 'a' exists in the contents of $line).
A 'better' solution for this might be an array of arrays (AoA), with the patterns in the order that you wish to apply them: ( [ a => 'b' ], [ b => 'c' ] ), and then stepping through the set of replacements in the expected order. --MidLifeXis
In Section
Seekers of Perl Wisdom
|
|