Yeah, I know what you're saying... This is what I have (and what I'm trying to run away from):
# parses HTML files as templates
#################################################
sub MakeHTML {
my ($file,%HTML) = @_;
my ($line,$tag,$html);
# open HTML file
open(READ,$file) || return(0);
foreach $line (<READ>) {
foreach $tag (keys %HTML) {
# substitute tags
$line =~ s/\[$tag\]/$HTML{$tag}/gi;
}
# gather parsed HTML
$html .= $line;
}
close(READ);
return($html);
}
# assign things like
$STUFF{'myname'} = 'John Burbridge';
$STUFF{'myage'} = 26;
# then print it
my $html = MakeHTML('/path/to/template.htm',$STUFF)
or Errors('couldnt parse the template');
print "Content-type: text/html\n\n";
print $html;
and the template file would look like this:
<html><body>
My name is [myname] and I am [myage] years old.
</body></html>
Sure it looks pretty simple and handy at 1st glance, but beleive me: ITS A BAD HABIT. I had to learn this the hard way...