- Messages
- 4,467
- Reaction score
- 95
- Points
- 0
I started a small project in perl recently, a survey generator. Basically is loads the survey from a XML file and generates the interface from the XML. However, I am having problems with the hashrefs. I would greatly appreciate if someone could help me out on this.
basically, the $surveyMetaData is being set to an empty hash, when I want it to reference (or hold) the value of $list->{survey}->{$survey}.
Code:
#!/usr/bin/perl -w
use HTML::Template;
use CGI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use XML::Simple;
use Data::Dumper;
########################
# MUST EDIT FOLOWING #
########################
# path to the data directory
my $dataDir = "PATH/TO/WHERE/THE/SURVEYS/ARE/";
########################
# DO NOT EDIT #
########################
my $query = new CGI;
my $template = HTML::Template->new(filename => 'survey.tmpl', path => $dataDir);
my $XML = new XML::Simple;
my $survey = $query->param('survey');
my $list = $XML->XMLin($dataDir . "surveys/list.xml", KeyAttr => "id");
if (exists $list->{survey}->{$survey}) {
my $surveyMetaData = $list->{survey}->{$survey};
} else {
$template->param(TITLE => 'ERROR', CONTENT => 'ERROR (0x0): Undefined survey ID.');
print "Content-Type: text/html\n\n", $template->output;
exit;
}
my $surveyData = $XML->XMLin($dataDir . "surveys/" . $surveyMetaData->{file} . ".xml", KeyAttr => "id");
print "Content-Type: text/html\n\n", $template->output;
basically, the $surveyMetaData is being set to an empty hash, when I want it to reference (or hold) the value of $list->{survey}->{$survey}.