Welcome to the Monastery | |
PerlMonks |
[bugs?] perldoc perlre, \G and pos()by LanX (Saint) |
on Sep 29, 2009 at 12:50 UTC ( [id://798113]=perlquestion: print w/replies, xml ) | Need Help?? |
LanX has asked for the wisdom of the Perl Monks concerning the following question:
IMHO this code example in perlre#Assertions is wrong or am I missing something?
Note that the rule for zero-length matches is modified somewhat, in that contents to the left of \G is not counted when determining the length of the match. Thus the following will not match forever: The while loop tries to match $_ not $str. so this works like it should
BUT what's really confusing me is that pos($str) is empty afterwards! Now appending this code to the latter
produces Use of uninitialized value in print at ... line 6. and an endless loop! OK ... now at the same time running this code:
produces but no endless loop! Sorry??? if pos() is uninitialized why does it produce in one case an endless loop and in another it doesn't?
Cheers Rolf UPDATE: Yes, I know that:
Currently, the "\G" anchor is only fully supported when used to anchor to the start of the pattern.(perlretut)... but pos() is defined to be the position after the last match, thus in our case with a final \G in the pattern it shouldn't change at all... IMHO there's no reason why this shouldn't work... and most probably this bug in pos is the source of the problem!
Back to
Seekers of Perl Wisdom
|
|