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

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

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

Replies are listed 'Best First'.
Re^7: [bugs?] perldoc perlre, \G and pos()
by ikegami (Patriarch) on Sep 29, 2009 at 16:07 UTC

    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

        you still haven't looked at the code I posted. With pos==0 it doesn't match

        I chose to explain why it matches endlessly. Will you stop telling me it doesn't match. I'm not interested in that case.

        which is evidently a bug!

        The bug is in your code. So what if Perl behaves oddly when provided with irrational inputs. Fix the bug in your code and it's a non-issue.