Author of:
and maintainer of:
Yesterday my friend Allan mailed me a script, he could not understand did not work for me to have a look at.
After debugging using the Perl debugger, trying all kind of tricks and reading some documentation, I started to suspect a bug in Perl, when I later talked to him, he had made an even smaller version of the and he mailed it to me.
I ended up writing my own barebones version of the demo, which demonstrates the problem:
use strict;
my $str = q(
J:somestring
I:someother
);
my $i = 0;
my $err = "\t### ERR ###\n\tNo match\n";
my $success = "\tsuccess...\n";
foreach my $key ("J","I") {
my $str2 = $str;
print "### RUN 1/".++$i." ###\nTesting \$str... looking for $key\n";
if ($str =~ m/^$key:.+/gm) {
print "$success\n";
} else {
print "$err\n";
}
print "Testing \$str2... looking for $key\n";
if ($str2 =~ m/^$key:.+/gm) {
print "$success\n";
} else {
print "$err\n";
}
}
foreach my $key ("I","J") {
my $str2 = $str;
print "### RUN 2/".++$i." ###\nTesting \$str... looking for $key\n";
if ($str =~ m/^$key:.+/gm) {
print "$success\n";
} else {
print "$err\n";
}
print "Testing \$str2... looking for $key\n";
if ($str2 =~ m/^$key:.+/gm) {
print "$success\n";
} else {
print "$err\n";
}
}
The problem see to be the
This is the output:
### RUN 1/1 ###
Testing $str... looking for J
success...
Testing $str2... looking for J
success...
### RUN 1/2 ###
Testing $str... looking for I
success...
Testing $str2... looking for I
success...
### RUN 2/3 ###
Testing $str... looking for I
### ERR ###
No match
Testing $str2... looking for I
success...
### RUN 2/4 ###
Testing $str... looking for J
success...
Testing $str2... looking for J
success...
If you alter the string so the part containing 'I' comes before the part that contains 'J', the problem is with 'J'.
I have searched for the string 'regex' at rt.perl.org only to be presented with 72 tickets. I have looking through some of these, but I have not yet found out whether this bug is already known.
You keep matching against $str (Score:1)
So if you unroll your loops, you get basically this.
Look for, at the beginning of the string, "J:", followed by a bunch of stuff that isn't a newline. (.+ with
Look for, at the beginning of the string (where we left off), "I:", followed by a bunch of stuff that isn't a newline. Did you succeed? *Remember this spot and proceed*.
Look for, at the beginning of
From perlop (Score:1)