in reply to Substitution backreference woes
It's important to remember is that the replacement portion of a s/search/replace/ substitution (the part between the second // pair) exactly obeys the single- or double-quote interpolation rules of any single- or double-quoted literal. The substitution above could be re-written as
s{search}"replace"
or, if no interpolation was wanted, as
s{search}'replace'
instead.
String interpolation in Perl does not nest. (A Perl string is not an AST macro.) If I start with a string
my $s = 'fee \n fie $foo fum';
(again, single-quoting completely defeats interpolation), I get a string that is literally
fee \n fie $foo fum
If I then intepolate this string into another string, the second string is not re-scanned after interpolation to handle anything that looks like it might possibly be further interpolated.
c:\@Work\Perl>perl -wMstrict -le "my $s = 'fee \n fie $foo fum'; print qq{'$s'}; ;; my $t = qq{zit $s zot}; print qq{'$t'}; " 'fee \n fie $foo fum' 'zit fee \n fie $foo fum zot'
You may be looking for some sort of text templating system, e.g., Text::Template. The s///ee 'trick' shown by LanX above works, but lacks generality.
Give a man a fish: <%-(-(-(-<
|
|---|