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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |