morgon has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Matching with /g: Is this a bug?
by choroba (Cardinal) on May 27, 2013 at 14:47 UTC | |
Re: Matching with /g: Is this a bug?
by CountZero (Bishop) on May 27, 2013 at 15:10 UTC | |
by morgon (Priest) on May 27, 2013 at 15:18 UTC | |
by choroba (Cardinal) on May 27, 2013 at 15:23 UTC | |
Re: Matching with /g: Is this a bug?
by Athanasius (Archbishop) on May 27, 2013 at 15:03 UTC | |
by choroba (Cardinal) on May 27, 2013 at 15:21 UTC | |
Re: Matching with /g: Is this a bug?
by kcott (Archbishop) on May 27, 2013 at 15:30 UTC | |
Re: Matching with /g: Is this a bug?
by ww (Archbishop) on May 27, 2013 at 15:07 UTC | |
Re: Matching with /g: Is this a bug?
by ikegami (Patriarch) on May 29, 2013 at 20:33 UTC |
Back to
Seekers of Perl Wisdom