can someone explain to me the following behaviour or confirm that it is a bug:
The above code prints "hubba1hubba2" as expected.use strict; my $s = <<end; hubba1 bubba hubba2 end print $s =~ /(hubba\d)/gm;
But when I do this
it only prints "hubba2", because (I assume) the second match only starts where the first match matched (ie pos is not reset).use strict; my $s = <<end; hubba1 bubba hubba2 end $s =~ /bubba/gm; print $s =~ /(hubba\d)/gm;
When I do this:
I get the correct behaviour again - I assume that the unsuccessul match attempt resets pos here.use strict; my $s = <<end; hubba1 bubba hubba2 end $s =~ /bubba/gm; $s =~ /no match/gm; print $s =~ /(hubba\d)/gm;
I am using 5.14.2 and my understanding is that the behaviour in the second case is a bug or is there something I don't understand?
Many thanks! Update:
Corrected the code-examples
In reply to Matching with /g: Is this a bug? by morgon
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |