in reply to Interpolating $var in a $string

Try the reverse approach to fully leverage the power of perl

Here's something to consider ... instead of loading a template string into your perl script that has some data, why not load the data into your perl script that has some template string? It's just as quick and dirty, it obviates the need to use a Templating module (if you're opposed to that) and it's still relatively 'readable' for a simple fill-in-the-blank type document. For example:

### INIT pragma and lib use strict; use warnings; use YAML; ### INIT vars my $sRaw = join '', (<DATA>); my $d = YAML::Load($sRaw)->{data}[0]; ### OUTPUT template print q% This is my template. I am %.$d->{fname}.q% %.$d->{lname}.q%, %.$d->{job}.q%. I own %.$d->{assets}.q%. Dont be a *@#!! You can make big $$bucks$$ by writing template code!! %; __DATA__ data: - fname: Elmer J. lname: Fudd job: millionaire assets: a mansion and a yacht

Your interpolated vars look like this:

%.$d->{foo}.q%
It's a bit more typing than just ...
$foo
but less of a security risk, and the 'q' operator will not interpolate *anything* except your interpolated vars. This is nice when you have an output template that includes funky metacharacters or anything else that might trip up your script. Also, you don't have to use the percent symbol, you can use any character that you know will never appear in your output template.

When you think about it, it's rather silly to write "template munging code" ... because perl already does that quite well! Instead, focus on "data munging code" ...
There's a million possible data formats out there.
There's a multitude of ways to fill in a template (otherwise why would you generalize it into a template to begin with?).
There's a million ways to get data into a perl script, and you can make them interchangeable without having to change a single line of your template string.

Just some bits to consider