in reply to Perl bug or feature?
It's not a bug in Perl but a bug in your expectations. The empty RE // always matches, see perlre resp. perlop. And the first match has nothing to do with it, as removing it still produces all matches:
#!/usr/bin/perl my @strings = ('testing','','testing','testing'); foreach my $string (@strings) { my $q = $string; my $test = 'testing'; warn "$test =~ /$q/?"; warn $test =~ /\Q$q\E/; } __END__ testing =~ /testing/? at tmp.pl line 8. 1 at tmp.pl line 9. testing =~ //? at tmp.pl line 8. 1 at tmp.pl line 9. testing =~ /testing/? at tmp.pl line 8. 1 at tmp.pl line 9. testing =~ /testing/? at tmp.pl line 8. 1 at tmp.pl line 9.
Update: Actually, while my reply is not untrue, the real cause is told by Anonymous Monk below. The empty match will repeat the last match.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl bug or feature?
by JavaFan (Canon) on Oct 25, 2010 at 17:23 UTC |