in reply to Re^3: Bizarreness in ?PATTERN? and g
in thread Bizarreness in ?PATTERN? and g

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

Replies are listed 'Best First'.
Re^5: Bizarreness in ?PATTERN? and g
by Mr. Muskrat (Canon) on Jun 04, 2004 at 05:24 UTC

    That is how the g modifier works in scalar context. The match doesn't fail in the first or second attempt nor do you use reset so pos() is not reset and the next pattern will match where the last one left off. Read the entire section of perlop that deals with m/PATTERN/cgimosx & /PATTERN/cgimosx because it explains it very clearly.

Re^5: Bizarreness in ?PATTERN? and g
by halley (Prior) on Jun 04, 2004 at 13:17 UTC
    The intent of the interaction between /g and pos() is to allow you to build parsers that "consume" a string. You read the first part, and if that matches, you read the second part, and if that fails, you try an alternative for the second part, and so on.

    Check out the Mastering Regular Expressions book for some ideas on how to keep this in mind, and take advantage of it for parsing tasks.

    --
    [ e d @ h a l l e y . c c ]