yegg has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl my @strings = ('testing','','testing','testing'); foreach my $string (@strings) { print "\nSTRING: $string\n"; my $string2 = 'http'; $string2 =~ /^h(.*)/o; my $q = $string; my $test = 'testing'; warn $test =~ /\Q$q\E/; }
I finally got to the bottom of the problem I reported at http://www.perlmonks.org/?node_id=867059 (thx to everyone who commented), and I distilled it to the above test case.
Here's what I think is happening. If you have a an /o regex with a capture clause and it captures something, and then you run a a second regex with a variable, but it set to '', then it uses the first compiled regex instead (and thereafter), and doesn't match as you'd expect as a result.
In this example, You'd expect line 14 to warn 1 then nothing, then 1 twice. Instead, you get 1, then nothing the rest of the time.
I'm running v5.8.9 on FreeBSD 7.0. FWIW, I also filed a perlbug here: http://rt.perl.org/rt3/Ticket/Display.html?id=78564
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl bug or feature?
by Corion (Patriarch) on Oct 25, 2010 at 17:10 UTC | |
by JavaFan (Canon) on Oct 25, 2010 at 17:23 UTC | |
|
Re: Perl bug or feature?
by Anonymous Monk on Oct 25, 2010 at 17:19 UTC | |
by bart (Canon) on Oct 26, 2010 at 11:24 UTC | |
|
Re: Perl bug or feature?
by JavaFan (Canon) on Oct 25, 2010 at 17:27 UTC | |
|
Re: Perl bug or feature?
by AnomalousMonk (Archbishop) on Oct 25, 2010 at 19:33 UTC | |
|
Re: Perl bug or feature?
by ig (Vicar) on Oct 26, 2010 at 04:51 UTC |