in reply to Interpolate into replacement with s//?
$replace contains a template. Therefore, you need a template engine to process it. The only existing template module I know that can process that language is String::Interpolate. (Yeah, it has a weird interface.)
Alternatively, if $replace actually contained a string literal (i.e. Perl code), you could use eval to evaluate it.
$string = 'ABC'; $search = qr/^(A)/; $replace = '"$1Z"'; $string = s{$search}{ my $replacement = eval($replace); die $@ if $@; $replacement }eg; say $string;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Interpolate into replacement with s//?
by tchrist (Pilgrim) on Nov 09, 2011 at 20:54 UTC | |
by philkime (Beadle) on Nov 09, 2011 at 21:18 UTC | |
by ikegami (Patriarch) on Nov 09, 2011 at 21:31 UTC | |
by philkime (Beadle) on Nov 10, 2011 at 09:14 UTC | |
by ikegami (Patriarch) on Nov 14, 2011 at 19:15 UTC | |
|