develooper Front page | perl.perl5.porters | Postings from March 2013

Re: Is this a /^*/ bug?

Thread Previous | Thread Next
From:
demerphq
Date:
March 25, 2013 16:02
Subject:
Re: Is this a /^*/ bug?
Message ID:
CANgJU+U_J9Ku7wv+fZHrTK1-TUmwp9jJEfSR31os=CSMPhb_QA@mail.gmail.com
On 25 March 2013 16:55, Tom Christiansen <tchrist@perl.com> wrote:
> I realize this is nonsense, but I wonder if it is not a bug.  Shouldn't the
> overall pattern still fail, not succeed?
>
>     % perl -WE 'say "foo.bar" =~ /^.*.bar$/ || "FAIL"'
>     1
>
>     % perl -WE 'say "foo.bar" =~ /^*.bar$/ || "FAIL"'
>     ^* matches null string many times in regex; marked by <-- HERE in m/^* <-- HERE .bar$/ at -e line 1.
>     1
>
>     % perl -WE 'say "foo.bar" =~ /(^*).bar$/ || "FAIL"'
>     ^* matches null string many times in regex; marked by <-- HERE in m/(^* <-- HERE ).bar$/ at -e line 1.
>     1
>
>     % perl -WE 'say "foo.bar" =~ /^.bar$/ || "FAIL"'
>     FAIL
>
> Tested with v5.8.8, v5.14.0, v5.16.0, and v5.17.0-352-g3630f57.

There might be a case to change this from a warning to a fatal error.

But its a warning, and as such no, I dont think the pattern should fail:

$ perl -WE 'say "foo.bar" =~ /^*.bar$/ || "FAIL"' 2>&1 | splain
^* matches null string many times in regex; marked by <-- HERE in m/^* <-- HERE
	.bar$/ at -e line 1 (#1)
    (W regexp) The pattern you've specified would be an infinite loop if the
    regular expression engine didn't specifically check for that.  The <-- HERE
    shows in the regular expression about where the problem was discovered.
    See perlre.

1

Consider that ^* means "match at the start of the string 0 or more
times". So the pattern succeeds because it matches 0 times.

It warns because it could match at the same spot an infinite number of times.

All of this is as I expect.

Yves




-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About