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

Re: [perl #119095] Empty regular expression does not match in somecases

Thread Previous | Thread Next
From:
H.Merijn Brand
Date:
July 31, 2013 14:47
Subject:
Re: [perl #119095] Empty regular expression does not match in somecases
Message ID:
20130731164659.5586b1ac@pc09.procura.nl
On Wed, 31 Jul 2013 07:34:07 -0700, Petr Pisar (via RT)
<perlbug-followup@perl.org> wrote:

> # New Ticket Created by  Petr Pisar 
> # Please include the string:  [perl #119095]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=119095 >
> 
> 
> Hello,
> 
> this code:
> 
> q{"} =~ m/"/;
> 
> if (q{a} =~ m//) {
>     print "TRUE\n";
> } else {
>     print "FALSE\n";
> }
> 
> should print TRUE, but it prints FALSE.

Mope.

$ perldoc perlreref

   If 'pattern' is an empty string, the last successfully matched regex is
   used. Delimiters other than '/' may be used for both this operator and the
   following ones. The leading "m" can be omitted if the delimiter is '/'.

> In other words, empty regular expression does not match. There is some side
> effect because it depends on previous regular match (the first line). If
> I change the first line anyhow, like m/"/ changing to m/./, the code starts
> working correctly.
> 
> I observe this behaviour with somewhat patched 5.16.3, vanilla 5.18.0
> and current blead.
> 
> You can use this one-liner instead:
> 
> $ perl -e 'q{"} =~ m/"/; if (q{a} =~ m//) { print qq{TRUE\n} }'


-- 
H.Merijn Brand  http://tux.nl   Perl Monger  http://amsterdam.pm.org/
using perl5.00307 .. 5.19   porting perl5 on HP-UX, AIX, and openSUSE
http://mirrors.develooper.com/hpux/        http://www.test-smoke.org/
http://qa.perl.org   http://www.goldmark.org/jeff/stupid-disclaimers/

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