Since what you have in the here doc looks suspiciously like XML, the right way to do it would be to leverage one of the XML modules such as XML::Twig or XML::LibXML.

You could also do it with s/// but you would be making a rod for your own back.

It turns out that it wasn't obvious what you wanted to do here after all. :-)

The problem (which you haven't spelled out) is that the here doc interpolates when you set $a so your initial $y is never changed. One solution is not to interpolate but to use a placeholder scalar (which could just be "$y" again) and then eval the here document.

#!/usr/bin/env perl use strict; use warnings; my ($y, $out); $y = 'baby'; my $hd = <<'EOT'; Hello $y! EOT eval "\$out = qq{$hd}"; print $out; $y = 'world'; eval "\$out = qq{$hd}"; print $out;

But that's a bit crude. Far better to use a proper templating system.


In reply to Re: Enlarging scalars by hippo
in thread Enlarging scalars by WisDomSeeKer34

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.