in reply to Re: Regex Optimization Question
in thread Regex Optimization Question

Using $1, $2, etc without knowing if the regexp matched is dangerous. For example,
foreach ('foo', 'bar') { /(oo)/; print("$1\n"); }
outputs
oo oo

Replies are listed 'Best First'.
Re^3: Regex Optimization Question
by aweeraman (Novice) on Mar 23, 2006 at 20:28 UTC
    True. I've found that in these cases, doing the regex with pattern memory in its own code block works.
    foreach ('foo', 'bar') { { /(oo)/; print("$1\n"); } }
      I didn't know that. Neat!