There's a lot to say here. The fact is, I'm still learning, and part of the learning process is re-working what you have. There isn't anything broken about this routine, for example, but writing the header to an html page is not the fancy part of this evolving toolset. As I'm now working through the Alpaca book, I want to try fancier things with language than what I can find here. Furthermore, I don't understand something until I've re-written it a few times....
sub write_header {
use strict;
use Text::Template;
my $rvars = shift;
my %vars = %$rvars;
# get time
my $now_string = localtime;
$vars{"date"} = $now_string;
my $header = $vars{"header"};
my $template2 = Text::Template->new(SOURCE => $header)
or die "Couldn't construct template: $!";
my $result2 = $template2->fill_in(HASH => \%vars);
return \$result2;
}
I also wrote a utility script that clones the template and imports data, so that I'm not betting the whole house every time a few lines change here or there. Always curious to hear what works for other people.