Similar problem, different context. In perl, double quotes
causes interpolation, so in
$r = "$1 world";
$1 is substituted with whatever was matched in a previous
regex. To prevent interpolation, use single quotes.
That doesn't solve the whole problem, however. Now we need
to substitute the strings, including metacharacters, into
s///. To interpolate, then substitute, I'll use an eval:
$s = '(hello)';
$r = '$1 world';
$_ = 'hello';
eval "s/$s/$r/";
print $_;
A good general rule to follow is to use single quotes
if you want the string as is, and use double quotes if
you want interpolation.
-Mark | [reply] [d/l] [select] |
Thanks, it was the eval function that does the trick. Believe me, I have tried quotes, double quotes and everything that goes along with it many times before posting my question here but it never seemed to do what I wanted.
Thanks again !
Cheers,
Mario.
| [reply] |
| [reply] [d/l] |