Thanks, repson - is just what I was looking for. 8^)
Working code + markup below.
cheers,
Don
striving for Perl Adept
(it's pronounced "why-bick")
(template.pl)
#!/usr/bin/perl -wT
use strict;
use HTML::Template;
use HTML::Entities;
use CGI qw(:all); # use CGI::Pretty qw(:all);
use CGI::Carp qw(fatalsToBrowser); # debugging only - for production
+"use CGI::Carp;"
use Time::localtime;
use File::stat;
use vars qw(@urlsA @urlsB);
my $code = 'template.pl';
my $tmpl = 'template.tmpl';
my $template = HTML::Template->new(filename => "$tmpl");
my %urlhashA = (
'home' => '/',
'sitedocs' => '/doc/',
);
my %urlhashB = (
'Perl Monks' => 'http://www.perlmonks.org/',
'CPAN' => 'http://search.cpan.org/',
'Google' => 'http://www.google.com/',
'Cisco' => 'http://www.cisco.com/',
);
while (my ($name,$url) = each %urlhashA) {
push @urlsA, {
nameA => $name,
urlA => $url,
}
}
$template->param(urlloopA => \@urlsA);
while (my ($name,$url) = each %urlhashB) {
push @urlsB, {
nameB => $name,
urlB => $url,
}
}
$template->param(urlloopB => \@urlsB);
$template-> param(
codemod => ctime(stat($code)-> mtime),
tmplmod => ctime(stat($tmpl) -> mtime),
servname => $ENV{'SERVER_NAME'},
);
print header, $template->output;
(template.tmpl)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE><!-- tmpl_var name=servname --></TITLE>
</HEAD>
<BODY>
<!-- tmpl_loop name="urlloopA" -->
<A HREF="<!-- tmpl_var name="urlA" -->">
<B><!-- tmpl_var name="nameA" --></B>
</A>
<!-- /tmpl_loop -->
<P>
<!-- tmpl_loop name="urlloopB" -->
<A HREF="<!-- tmpl_var name="urlB" -->">
<!-- tmpl_var name="nameB" -->
</A>
<BR>
<!-- /tmpl_loop -->
<P>
Code update <!-- tmpl_var name=codemod -->
<BR>
Template update <!-- tmpl_var name=tmplmod -->
</BODY>
</HTML>
|