in reply to Re: Variable substitute and capturing
in thread Variable substitute and capturing
That won't work, since you didn't escape $search or $replace. Also, you're needlessly recompiling $search if it's already compiled. Use the following instead:
$escaped_replace = '$1 (\$1.00)'; # Escape \, $, @ and / eval "\$title =~ s/\$search/$escaped_replace/";
But since the only thing that needs to be compiled is the replace expression (not the entire substitution), the following is even better:
$quoted_replace = '"$1 (\$1.00)"'; # Escape \, $, @ and /. Add quotes $title =~ s/$search/eval $quoted_replace/e;
Of course, not using eval EXPR would be even better. In other words, a templating system would be even better. I mentioned this and posted an example in the thread to which I linked in my other post.
Update: Added "or $replace".
Update: Oops, davidrw is correct. $search doesn't need escaping.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Variable substitute and capturing
by davidrw (Prior) on Jan 16, 2006 at 16:54 UTC | |
by ikegami (Patriarch) on Jan 16, 2006 at 17:08 UTC |