Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
In your TestEK.txt file, you have all {[%tqu ... ]} sequences on the same line. In the second, real file, these sequences span two or more lines. You are processing the file line-by-line and matching your regex against each line, so if a {[%tqu ... ]} sequence spans multiple lines, the regex will never see it.
If the file is small, less than, say, several hundred megabytes and never likely to grow larger, it might be easiest to "slurp" the entire file at once as a string into a scalar variable and then do a single s/// against the variable, then write the string back out to the new file. Update: See also File::Slurp. Update 2: Here's a test:
Update 3: Update 2 contains a rookie mistake: using greedy .* instead of the lazy .*? version. Here's a version that will actually work with a single long string. The previous version would delete everything between the absolute first {[%tqu and the absolute last ]} sequence in the file. Actually, something like my $regex = qr{ {\[%tqu [^\]]* ]} }xms; might even be preferable as long as there are guaranteed to be no ] (right-square-bracket) characters in the sub-strings to be removed, but let's leave it at that for now. Give a man a fish: <%-{-{-{-< In reply to Re^3: Substitution don't work
by AnomalousMonk
|
|