develooper Front page | perl.perl5.porters | Postings from June 2021

Re: qr'$foo' and unescaped $ signs

Thread Previous | Thread Next
From:
Eirik Berg Hanssen
Date:
June 29, 2021 15:39
Subject:
Re: qr'$foo' and unescaped $ signs
Message ID:
CAHAeAG7k81ydAuAr+vXGCMWaPJH-47gvWLOCtTRj_RaNtO9w7w@mail.gmail.com
On Tue, Jun 29, 2021 at 4:31 PM Nicholas Clark <nick@ccl4.org> wrote:

> So I guess, the question is:
>
> If the PV stored for a regex has an *unescaped* dollar sign in it it *has*
> to have originated from a regex written with '' ?
>

  I'm not sure I follow you all the way, but I don't think so.  It could
come from an interpolated variable:

eirik@rustybox[17:33:04]~$ perl 2>&1 | grep PV
use Devel::Peek;
Dump($_) for qr'$foo', qr/${\q($)}foo/;
__END__
    PV = 0x55d52be518a0 "(?^:$foo)"
      PV = 0x55d52be518a0 "(?^:$foo)"
    PV = 0x55d52be714c0 "(?^:$foo)"
      PV = 0x55d52be714c0 "(?^:$foo)"
eirik@rustybox[17:33:24]~$


> 1) the *only* way that could have got there was by being written as qr''
>

  If I read you right, no, not quite.


> 2) the *only* way to convert that back to a regex is to output qr''
>    (ie there exists no escaping syntax capable of recreating it inside
> qr//)
>

  The only *other* way I know of, is through a variable.

  Perhaps Data::Dumper should output qr/(?^:${\q($)}foo)/;instead?


Eirik

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