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:  <%-(-(-(-<


In reply to Re: Substitution backreference woes by AnomalousMonk
in thread Substitution backreference woes by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.