I'm writing some code that generates HTML pages from templates. I'd been prototyping the system with here documents, when I got the wacky idea that I might put the here doc text in a file, slurp it into a string, and have a cheap template. I probably will go with one of the excellent \w+::Template modules, but first I want to play with the idea of "templates on the cheap."

What I want, basically, is double-quote interpolation of variable contents, as the text files I have contain lines of the form

<a href='mailto: $maintainer'>Send email</a> to site maintainer.

my idea so far:

use strict; my $maintainer = 'root@god.com'; # I've also tried making this a globa +l, so I don't think it's scoping my $data; { local $/; open FILE, "filename" or die "ha ha! :$!\n"; $data = <FILE>; close FILE; }

But that leaves $data</a> as is (i.e. with a literal <code>$maintainer in it.

Out of (at this point) pure curiosity, how would I get the value of $maintainer to interpolate in there? (I've tried variations on eval and here-doc quoting, including the too-good-to-have-worked-anyhow $data = "$data"; with no sucess).

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Templates on the cheap? by arturo

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.