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

Re: [perl #119793] /x on \Q#foo\E doesn't match '#foo', # becomes special

Thread Previous
From:
Eric Brine
Date:
September 18, 2013 15:27
Subject:
Re: [perl #119793] /x on \Q#foo\E doesn't match '#foo', # becomes special
Message ID:
CALJW-qFiFjNr2ZdzsyswXHPxLag7zritdNOR_NEJrNQ+LR07rw@mail.gmail.com
On Wed, Sep 18, 2013 at 10:56 AM, Nicholas Clark <nick@ccl4.org> wrote:

> Nice bug. I'm not sure if the behaviour is as simple as # being a "dead"
> character or not. If differs depending on whether \E is present:
>
> $ perl -e 'warn "a# " =~ /\Qa# \E/ ? "M" : "."'
> M at -e line 1.
> $ perl -e 'warn "a# " =~ /\Qa# / ? "M" : "."'
> M at -e line 1.
> $ perl -e 'warn "a# " =~ /\Qa# \E/x ? "M" : "."'
> . at -e line 1.
> $ perl -e 'warn "a# " =~ /\Qa# /x ? "M" : "."'
> M at -e line 1.
>

Nice indeed. Easy to see with qr//

$re = qr/\Q#abc\E/x;  print "$re\n";  print '#abc' =~ /$re/ || 0, "\n";
$re = qr/\Q#abc/x;    print "$re\n";  print '#abc' =~ /$re/ || 0, "\n";
$re = qr/\Qabc\E/x;   print "$re\n";  print 'abc'  =~ /$re/ || 0, "\n";

(?^x:\#abc\\E)
0
(?^x:\#abc)
1
(?^x:abc)
1

Thread Previous


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