#!/usr/bin/perl use strict; use warnings; use HTML::Template qw(); use CGI qw(); my $fName = 'sample.html'; open my $temp, '>', $fName or die "Can't create $fName: $!\n"; print $temp <<'HTML'; <TMPL_VAR name="title">
">
HTML close $temp; my $tmpl = HTML::Template->new(filename => $fName); my @fields = qw(Hello Goodbye Friend Adios Amigo); my @loopParams = map {{div => $_}} @fields; print CGI::header(); $tmpl->param(title => "testme"); $tmpl->param(divname => 'div-test'); $tmpl->param(divs => \@loopParams); print $tmpl->output(); #### Content-Type: text/html; charset=ISO-8859-1 testme
Hello
Goodbye
Friend
Adios
Amigo