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

Re: qr'$foo' and unescaped $ signs

Thread Previous | Thread Next
Eirik Berg Hanssen
June 29, 2021 15:39
Re: qr'$foo' and unescaped $ signs
Message ID:
On Tue, Jun 29, 2021 at 4:31 PM Nicholas Clark <> 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/;
    PV = 0x55d52be518a0 "(?^:$foo)"
      PV = 0x55d52be518a0 "(?^:$foo)"
    PV = 0x55d52be714c0 "(?^:$foo)"
      PV = 0x55d52be714c0 "(?^:$foo)"

> 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?


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About