#!/usr/bin/perl

# import module
use dTemplate;

# create hash for template files
$templateDir = "../htdocs/templates";
%templates = ("form" => "form.tmpl", "option" => "option.tmpl");

# create dTemplate objects for each template $templates={}; foreach $name (keys(%templates)) {
	$templateName = $templateDir . "/" . $templates{$name};
	$templates->{$name} = dTemplate->new(file => $templateName); }

# set up option list
@countries = ("Australia", "New Zealand", "Japan", "Singapore", "China", "India", "Malaysia", "Thailand"); 

# parse option template and replace variable with array element # then loop and do it again # until $optionList contains the entire set of options foreach $c (@countries) {
	$optionList .= $templates->{option}->parse(ITEM => $c); }

# now parse the form template
$output = $templates->{form}->parse(OPTIONS => $optionList);

# print rendered version
print "Content-Type: text/html\n\n";
print $output;