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

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

Thread Next
Petr Pisar
July 31, 2013 14:34
[perl #119095] Empty regular expression does not match in some cases
Message ID:
# New Ticket Created by  Petr Pisar 
# Please include the string:  [perl #119095]
# in the subject line of all future correspondence about this issue. 
# <URL: >


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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About