in reply to Bizarreness in ?PATTERN? and g

It's by design. I did the same thing once.

From perlop:

?PATTERN? This is just like the /pattern/ search, except that it matches only once between calls to the reset() operator. This is a useful optimization when you want to see only the first occurrence of something in each file of a set of files, for instance. Only ?? patterns local to the current package are reset. while (<>) { if (?^$?) { # blank line between header and body } } continue { reset if eof; # clear ?? status for next file } This usage is vaguely deprecated, which means it just might possibly be removed in some distant future version of Perl, perhaps somewhere around the year 2168.

The solution? Use a different delimiter, but I'm sure you already know that ;)

Replies are listed 'Best First'.
Re^2: Bizarreness in ?PATTERN? and g
by BUU (Prior) on Jun 04, 2004 at 05:06 UTC
    No no no, you're missing my point. I realize that ?? only matches once, but shouldn't the second regex be seperate from the first regex?
    /regex1/ /regex2/
    Regex1 and 2 shouldn't have anything to do with each other, should they? But in my example, the two ??'s are affecting each other, but they're completely seperate!

      If you want them separate then remove the g modifier.

      $_="a1 a2 a3"; while(?a(\d)?){ print $1; } while(?a(\d)?){ print $1; } __END__ 11

      Updated to add in the snippet.

        I realize that, but why is one affecting the other?