使用HTML::Template
。
#!/usr/bin/perl
use strict;
use warnings;
use HTML::Template;
my $template_text = <<EO_TMPL;
<TMPL_LOOP FILES>
<file>
<state><TMPL_VAR STATE></state>
<timestamp><TMPL_VAR TIME></timestamp>
<location><TMPL_VAR LOCATION></location>
</file>
</TMPL_LOOP>
EO_TMPL
my $tmpl = HTML::Template->new(scalarref => \$template_text);
$tmpl->param(
FILES => [
{ state => 'one', time => 'two', location => 'three' },
{ state => 'alpha', time => 'beta', location => 'gamma' },
]);
print $tmpl->output;
輸出:
<file>
<state>one</state>
<timestamp>two</timestamp>
<location>three</location>
</file>
<file>
<state>alpha</state>
<timestamp>beta</timestamp>
<location>gamma</location>
</file>
答案正是我需要的。 – 2009-08-20 13:26:02
嘿!好的HTML'模板! – innaM 2009-08-20 15:37:34