saintmike has asked for the wisdom of the Perl Monks concerning the following question:
what's the best way to tap into Perl's double-quote-interpolation mechanism? Starting from strings like
(notice the single quotes in the second case), I'd like to get 'abc foo def' in $str.my $var = "foo"; my $str = 'abc $var def';
Now, you could do something like
but this will fail if $str contained a double-quote. You could escape literal double quotes before eval'ing and unescape them in the result -- but isn't there a better way to say "escape all variables in this string, just like double quotes would do"?my $newstr = eval "\"$str\"";
|
|---|