#!/usr/bin/perl -w use strict; use Template; # Define hash my %fruits= ( "naranja" => "naranja" , "limón" => "amarillo" ); # Simulate a file (this content should be separated normally, on a file) my $html = << 'EOT'; fruits and colors [%# The end string "-%" will remove empty lines from source code -%] [% FOREACH fruit IN fruits.keys -%] [% END -%]
Fruit Color
[% fruit -%] [% fruits.$fruit -%]
EOT # Create the template var: my $template=Template->new(); # Process the template, telling that fruits var inside the template is %fruits on perl code # and that $html has the template text: $template -> process (\$html,{ fruits => \%fruits }) || die $template->error(); # Read man Template to know more about this module