use strict; use warnings; use HTML::Template; my $template = HTML::Template->new( filename => 'html_template.tmpl' ); # set the VAR1 parameter $template->param( VAR1 => 'this is var 1' ); # create data for the table and set TESTLOOP my @loopdata; for( 0 .. 3 ) { push( @loopdata, { cell1 => "row $_ cell 1", cell2 => "row $_ cell 2" } ); } $template->param( TESTLOOP => \@loopdata ); # print to output file open( my $outfh, '>', 'html_template_output.html' ) or die "error opening output file:\n$!"; print $outfh $template->output(); close $outfh; # get output as a string of HTML my $output = $template->output(); print $output; #### This is a test template for HTML::Template Var1 =
Loop:
Cell 1 = Cell 2 =
##
## This is a test template for HTML::Template Var1 = this is var 1
Loop:
Cell 1 = row 0 cell 1 Cell 2 = row 0 cell 2
Cell 1 = row 1 cell 1 Cell 2 = row 1 cell 2
Cell 1 = row 2 cell 1 Cell 2 = row 2 cell 2
Cell 1 = row 3 cell 1 Cell 2 = row 3 cell 2