Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^3: Precompiling qr/.../o question

by hardburn (Abbot)
on Apr 02, 2008 at 19:11 UTC ( #678026=note: print w/replies, xml ) Need Help??

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.

Replies are listed 'Best First'.
Re^4: Precompiling qr/.../o question
by mr_mischief (Monsignor) on Apr 02, 2008 at 21:52 UTC
    Your wording read to me like you meant that the /o option was semantically redundant when used on the qr// itself.

    Now I realize you meant something else entirely. I think you're saying that as a feature it's been made redundant because there are better ways to accomplish that it was originally meant to do. I wouldn't disagree with that.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://678026]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2018-06-18 16:31 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (110 votes). Check out past polls.