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

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

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

    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.