David is correct about the syntax and the suggestion to use Template::Toolkit. Or another templating module.
Here's a simple example that generates a page from a template in the DATA section of a script.
Of course the real power comes when you keep separate template files and reuse and combine them.
#!perl
use strict;
use warnings;
use Template;
my $page_data = {
title => 'DL Demo',
data => [
{ terms => ['One Term'],
data => ['One Definition'],
},
{ terms => [qw( Many Terms )],
data => ['One Definition'],
},
{ terms => ['One Term'],
data => [qw( Many Definitions )],
},
],
};
my $tt = Template->new() or die "Ugh";
$tt->process(\*DATA, $page_data);
__DATA__
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
<title>[% title %]</title>
</head>
<body>
<div id="header">
<a href="/index.html" class="logo" alt="Home Page"></a>
<h1 class="headline">[% title %]</h1>
</div>
<div id="data">
<dl>
[% FOREACH item = data %]
[% FOREACH term = item.terms %] <dt> [% term %] </dt> [% END %]
[% FOREACH defdata = item.data %] <dd> [% defdata %] </dd> [% END %]
[% END %]
</dl>
</div>
</body>
</html>
Here's the output:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN">
<html>
<head>
<title>DL Demo</title>
</head>
<body>
<div id="header">
<a href="/index.html" class="logo" alt="Home Page"></a>
<h1 class="headline">DL Demo</h1>
</div>
<div id="data">
<dl>
<dt> One Term </dt>
<dd> One Definition </dd>
<dt> Many </dt> <dt> Terms </dt>
<dd> One Definition </dd>
<dt> One Term </dt>
<dd> Many </dd> <dd> Definitions </dd>
</dl>
</div>
</body>
</html>