in reply to Bizarreness in ?PATTERN? and g

Using ?? makes the whiles act like ifs.

perl> $_="a1 a2 a3"; if( /a(\d)/g ){ print $1, ' ', pos( $_ ); } if( /a(\d)/g ){ print $1, ' ', pos( $_ ); } 1 2 2 5

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re^2: Bizarreness in ?PATTERN? and g
by BUU (Prior) on Jun 04, 2004 at 05:03 UTC
    Well yeah, because the ??'s only return true. But surely when you repeat the code, it should be a completely seperate regex. Why should it's match be determined by the first regex?

      Because pos( $_ ) isn't being reset. Sort of like you had used /gc. I'm not sure if that constitutes a bug or not?


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "Think for yourself!" - Abigail
        Depends how you read
        except that it matches only once between calls to the reset() operator
        Does "matches" mean attempts to match only once (i.e. pos is completely unaffected when it no longer even try to match) or that later attempts to match will automatically fail (and pos is reset unless //c).

        Obviously the actual implementation agrees with the former interpretation. And my take is that it seems better that way.