Syntactic Confectionery Delight | |
PerlMonks |
Re^3: Invoke the Perl string interpolation engine on a string contained in a scalar variable.by davido (Cardinal) |
on Jan 15, 2019 at 20:32 UTC ( [id://1228618]=note: print w/replies, xml ) | Need Help?? |
In your example $y is a string of characters, but when you eval it with "eval $y", eval expects that string of characters to be Perl code. You need to give eval actual code to eval, not just a string of characters. Do this by wrapping that string of characters in Perl code (in quotes):
There's no great reason to have used the enquote sub rather than just inlining the buildup of the Perl-quoted string other than to attempt to make it more clear what the intent is. I could have just done this:
Or even...
In any case, the goal is to turn a raw string of characters into something that eval can reasonably compile as code that when evaluated returns the original string with interpolation in place. Dave
In Section
Seekers of Perl Wisdom
|
|