in reply to mmv-like hack in perl?
because the $replace is inserted into the "double-quoted" string on the right side, and not again rescanned to see if it has any variables to be replaced. So you get a literal $1 and so on.my $pattern = q/(...)(...)/; my $replace = q/$2-$1/; s/$pattern/$replace/g;
However, if you trust your invoker, you could try something like:
as long as the curly braces balance nicely.my $pattern = q/(...)(...)/; my $replace = q/$2-$1/; s/$pattern/qq{$replace}/eeg;
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: •Re: mmv-like hack in perl?
by mpd (Monk) on Apr 14, 2003 at 05:20 UTC | |
by merlyn (Sage) on Apr 14, 2003 at 10:13 UTC | |
by mpd (Monk) on Apr 14, 2003 at 16:08 UTC |