C:\perl\bin\perl.exe -T # Strictly speaking, taint checking is not required when you are # simply printing a Web page, but don't leave it out! use warnings; use strict; use HTML::Template; # Always be sure to encode anything that you print to a Web page, particularly # if it's not from a trusted source. One Porn image in your guestbook or properly # chosen meta tags can make your life a headache. use HTML::Entities; use CGI qw/:standard/; # Here we create a new template object and tell it where the template is my $template = HTML::Template->new( filename => 'template.tmpl' ); # We'll use toggle to set background colors my $toggle = 1; # This array contains a anonymous hash references that correspond to values in the template my @ENV; for ( sort keys %ENV ) { # This toggles $toggle between 0 and 1 $toggle ^= 1; push @ENV, { BGCOLOR => ( $toggle ? '#FFFFFF' : '#CCCCCC' ) , NAME => $_, VALUE => encode_entities( $ENV{$_} ) }; } $template->param( { HEADING => 'Some Environment Variables', ENV_VARS => \@ENV, BOOL => 1 } ); print header, $template->output;