use strict; use CGI qw(header); use Template; my $data = do {local $/; }; my $template = Template->new(); my $params = { questions => [ { question => 'What is your favorite number?', radio => [ { regular => 'question01', value => 'a', label => 5, }, { regular => 'question01', value => 'b', label => 7, }, { regular => 'question01', value => 'c', label => 13, }, { special => 'question01', value => 'd', label => 'Other', text => 'other', }, ], }, { question => 'Where did you hear about this product?', radio => [ { regular => 'question02', value => 'a', label => 'Friend', }, { special => 'question02', value => 'b', label => 'Magazine', text => 'magname', }, { regular => 'question02', value => 'c', label => 'Brochure', }, { special => 'question02', value => 'd', label => 'Other', text => 'other', }, ], }, ], }; print header; $template->process(\$data, $params) or die $!; __DATA__
[% FOR questions %]

[% question %]
[% FOR radio %] [% UNLESS special %] [% label %]
[% ELSE %] [% label%] (please specify:)
[% END %] [% END %] [% END %]