P
Paul Burton
I've got some code similar to this:
$a='$b="a_string"';
eval($a);
print $b;
For the above, this simply prints out "a_string".
Of course, I actually want something a little more interesting than
a_string. The output I actually want is the following string:
\$a_var
I thought I could achieve this by:
$a='$b="\\\$a_var"';
but this only produces the output:
\
I've managed to hack around this problem by generating my own special
string wherever I want a "\$" in the output, and using a string
substitution to put in the backslash:
$a='$b="\!\$a_var"'
eval($a);
$b =~ s/\!\$/\\\$/g;
which does the trick.
Is there a way of doing this without the substitution cludge, with some
clever combination of quotes and backslashes? I've tried a few things,
but nothing seems to work!
Cheers
Paul.
$a='$b="a_string"';
eval($a);
print $b;
For the above, this simply prints out "a_string".
Of course, I actually want something a little more interesting than
a_string. The output I actually want is the following string:
\$a_var
I thought I could achieve this by:
$a='$b="\\\$a_var"';
but this only produces the output:
\
I've managed to hack around this problem by generating my own special
string wherever I want a "\$" in the output, and using a string
substitution to put in the backslash:
$a='$b="\!\$a_var"'
eval($a);
$b =~ s/\!\$/\\\$/g;
which does the trick.
Is there a way of doing this without the substitution cludge, with some
clever combination of quotes and backslashes? I've tried a few things,
but nothing seems to work!
Cheers
Paul.