On 12/20/06, via RT aml @ rulezz. ru <perlbug-followup@perl.org> wrote:
> # New Ticket Created by aml@rulezz.ru
> # Please include the string: [perl #41115]
> # in the subject line of all future correspondence about this issue.
> # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41115 >
>
>
>
> This is a bug report for perl from aml@rulezz.ru,
> generated with the help of perlbug 1.35 running under perl v5.8.4.
>
>
> -----------------------------------------------------------------
> [Please enter your report here]
>
> Empty regular expression s/...// has a strange behaviour.
> Its result depends on previously evaluated regular expression.
> Look at the minimal proof of concept:
>
> #!/usr/bin/perl
>
> {
> print 'Correct result: ';
>
> &test;
> }
>
> {
> print 'Correct result: ';
>
> my $a = 'c';
> $a =~ s/c//;
>
> &test;
> }
>
> {
> print 'Incorrect result: ';
>
> my $a = 'd';
> $a =~ s/d//;
>
> &test;
> }
>
> sub test
> {
> print(('abc' =~ //) ? 'true' : 'false');
> print "\n";
> }
>
> Subroutine 'test' contains this strange regexp: sometimes it returns true, and sometimes false.
Hi,
This is actually documented behaviour. The empty pattern when used in
a m// or s/// match operator is special cased to mean the pattern used
in the last successful match.
If you truely wish to match nothing use the pattern /(?:)/
I will close this ticket as not-a-bug. Thanks for the report anyway.
Cheers,
Yves
ps: Yes this can be a trap that probably shouldn't have been
introduced, but its much too late to do anything about it now.
--
perl -Mre=debug -e "/just|another|perl|hacker/"