New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: builtin to apply double-quote interpolation to a scalar #16592
Comments
From @epaCreated by @epaSometimes you might want to make a template string with variables, and my $template = 'hello $name'; That trick with eval is awkward and unhygienic (what if $template Presumably the perl interpreter has an internal routine that performs my $s = interpolate($template); and get broadly the same semantics as the eval trick above, but I know there are many excellent templating systems out there. This is Perl Info
|
From @iabynOn Thu, Jun 21, 2018 at 02:40:44AM -0700, Ed Avis (via RT) wrote:
Well, not really. The lexer has code to understand a double-quoted string, "result=$foo[$x + 1]\n" gets lexed into the stream of tokens STRINGIFY so the parser thinks that the source code was actually 'result=' . $foo[$x + 1] . "\n". There is no simple function that can be exposed. -- |
The RT System itself - Status changed from 'new' to 'open' |
From @epaThanks. 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. |
From @iabynOn Mon, Jun 25, 2018 at 01:43:44AM -0700, Ed Avis via RT wrote:
It would have to be implemented using the underlying eval mechanism, which -- |
1 similar comment
From @iabynOn Mon, Jun 25, 2018 at 01:43:44AM -0700, Ed Avis via RT wrote:
It would have to be implemented using the underlying eval mechanism, which -- |
From @tonycozOn Mon, 25 Jun 2018 01:43:44 -0700, ed wrote:
You could just forbid some unusual character from the source. The $source =~ /\0/ and die; Tony |
Is this closable? |
I think so |
Migrated from rt.perl.org#133292 (status was 'open')
Searchable as RT133292$
The text was updated successfully, but these errors were encountered: