develooper Front page | perl.perl5.porters | Postings from August 2018

[perl #133292] Feature: builtin to apply double-quote interpolationto a scalar

From:
Tony Cook via RT
Date:
August 13, 2018 01:25
Subject:
[perl #133292] Feature: builtin to apply double-quote interpolationto a scalar
Message ID:
rt-4.0.24-28959-1534123553-871.133292-15-0@perl.org
On Mon, 25 Jun 2018 01:43:44 -0700, ed wrote:
> Thanks.  I forgot that string interpolation is converted to
> concatenation at compile time.  So the way to implement an
> interpolate() operator would be to make a new parser at run time and
> parse the argument's value as a doublequoted string, then evaluate
> that.  It would still be preferable to the trick with eval() because
> you don't need to worry about the delimiter character appearing in the
> string.

You could just forbid some unusual character from the source.  The
obvious choice is NUL:

   $source =~ /\0/ and die;
   my $result = eval "qq\0$source\0";

Tony

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=133292



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