Just another Perl shrine | |
PerlMonks |
Re: Matching with /g: Is this a bug?by kcott (Archbishop) |
on May 27, 2013 at 15:30 UTC ( [id://1035429]=note: print w/replies, xml ) | Need Help?? |
G'day morgon, "it only prints "hubba2", because (I assume) the second match only starts where the first match matched (ie pos is not reset)." Yes, your assumption is correct:
[length("hubba1\nbubba") == 12] and agrees with the pos documentation: "Returns the offset of where the last m//g search left off ..." In your last statement, you appear to be contradicting your previous, correct assumption: "... my understanding is that the behaviour in the second case is a bug or is there something I don't understand?" The code you've posted in the third case does not give "the correct behaviour"; it gives a syntax error. You probably meant /.../ instead of s/.../ (2 instances). Assuming you did, that also agrees with the pos documentation: "... search position is reset (usually due to match failure ..." -- Ken
In Section
Seekers of Perl Wisdom
|
|