in reply to Re^3: s/// with an empty pattern uses the previous pattern of a s///
in thread s/// with an empty pattern uses the previous pattern of a s///
That won't work if $pat is zero. Fix:
length($pat) && ($msg =~ s/$pat/$replace/mg);
I have to note this to try to scrape together a little dignity after having just posted a question on something in the man pages like a newbie coder :)
It's not well known, and it's easy to forget, because it's not a situation that's usually encountered. No dignity lost.
By the way compiling the pattern is not enough. I ran a test that showed $pat = qr//; /$pat/ is the same thing as m// even though the stringification of $pat is not an empty string.
|
|---|