http://www.perlmonks.org?node_id=678026


in reply to Re^2: Precompiling qr/.../o question
in thread Precompiling qr/.../o question

Sure, it technically works (probably because /o gets dragged along into qr// like any other regex option list), but it's still redundant and confusing.

The problem with /o is when you start with something harmless like this:

for (1 .. 5) { print "Match!\n" if $some_string =~ /very long regex/o; }

Then later you realize you need to add a loop variable to the regex:

for (1 .. 5) { print "Match!\n" if $some_string =~ /very long regex $_ more regex/o; }

Which results in the regex checking against '1' instead of the current loop var. This is almost never what you want, and has caused new and experienced programmers alike to waste many hours of debugging. That's why qr// was invented to Do the Right Thing.


"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.