in reply to Re^4: [bugs?] perldoc perlre, \G and pos()
in thread [bugs?] perldoc perlre, \G and pos()

1st Pass: It thinks it hasn't matched yet because pos == 0, so it matches, setting pos = 0.
2nd Pass: It thinks it hasn't matched yet because pos == 0, so it matches, setting pos = 0.
3rd Pass: It thinks it hasn't matched yet because pos == 0, so it matches, setting pos = 0.
...

  • Comment on Re^5: [bugs?] perldoc perlre, \G and pos()

Replies are listed 'Best First'.
Re^6: [bugs?] perldoc perlre, \G and pos()
by LanX (Saint) on Sep 29, 2009 at 15:35 UTC
    while() puts scalar context, so just _one_ try to match, and no match results in false!

    ...no repeated matches like in list context.

    Cheers Rolf

      You clearly see that it does match, so why do you keep saying it doesn't match in response to my explanation?

      1st Pass: It thinks it hasn't matched yet because pos == 0, so it matches, setting pos = 0.
      2nd Pass: It thinks it hasn't matched yet because pos == 0, so it matches, setting pos = 0.
      3rd Pass: It thinks it hasn't matched yet because pos == 0, so it matches, setting pos = 0.
      ...

      ...no repeated matches like in list context.

      The while isn't there for decoration. It's the one doing the repeating.

        you still haven't looked at the code I posted. With pos==0 it doesn't match, but there are two different kind of undefined pos (one after the variable is initialized, and one after the first match) which is evidently a bug!

        DB<168> $str="abcd" DB<169> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<170> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 0:: DB<171> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<172> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<173> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<174> pos($str)=0 DB<175> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 0:: DB<176> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<177> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<178> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<179> pos($str)=undef DB<180> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<181> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1: DB<182> print pos($str),":",scalar ($str=~/(.)\G/g),":",$1 :1:

        Cheers Rolf