Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: inserting HTML file in a PERL script

by Tortue (Scribe)
on May 29, 2005 at 19:04 UTC ( [id://461561] : note . print w/replies, xml ) Need Help??


in reply to Re^2: inserting HTML file in a PERL script
in thread inserting HTML file in a PERL script

Just to generalize the script I gave you... This replaces any variable in the template with its value in the program. It's a quick-and-dirty fix that may solve your problem if you're in a rush. Of course, as others have noted, it would be better if you used a proper templating system. Note also that this only works for simple scalar variables (e.g. $thing, $ZOWIE), not for more complicated variables such as array or hash elements (e.g., $var[$num] or $var{thing}).
my $template = snarf('template.htm'); while ($template =~ /(\$[:alpha:]\w*)/g) { my $variable_name = $1; my $value = eval $variable_name; $template =~ s/\Q$variable_name\E/$value/g; } print $template;