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

[perl #119095] Empty regular expression does not match in some cases

Thread Next
From:
Petr Pisar
Date:
July 31, 2013 14:34
Subject:
[perl #119095] Empty regular expression does not match in some cases
Message ID:
rt-3.6.HEAD-2552-1375281247-136.119095-75-0@perl.org
# 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.

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} }'

-- Petr

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