Welcome to the Monastery | |
PerlMonks |
Re: Multiline Regex replacement in Multiline fileby Athanasius (Archbishop) |
on Sep 15, 2014 at 07:34 UTC ( [id://1100564]=note: print w/replies, xml ) | Need Help?? |
Hello akamboj84, and welcome to the Monastery! You first create a dictionary mapping each search regex to its corresponding replacement text. Then, before searching, you change the search regex in two ways: (1) by concatenating all the search strings with |; (2) by applying the qr operator. So when you get to the substitution, if a match is found the dictionary lookup $dic{$matchkey} is guaranteed to fail, since the new value of $matchkey does not match any of the keys in the %dic hash! But even when this problem has been fixed,1 you will still be replacing the whole of the first user entry, including everything through to the final "engineer", with the single text REPLACE1. I doubt this is what you want. For the monks to help you further, you will need to specify the output you expect/desire. Update: 1For example:
Output:
Note that I had to add two doublequote characters to the second regex to get it to match. Hope that helps,
In Section
Seekers of Perl Wisdom
|
|