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:
$ perl -Mstrict -Mwarnings -E ' my $s = <<end; hubba1 bubba hubba2 end $s =~ /bubba/gm; say pos($s); print $s =~ /(hubba\d)/gm; ' 12 hubba2
[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 reply to Re: Matching with /g: Is this a bug?
by kcott
in thread Matching with /g: Is this a bug?
by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |