I am trying to process the results of a survey. I load the current results from an XML file, update them, then write them back to the file. I am get a 500 Internal Server Error when I run it from a browser, but it works fine in Windows and Linux on the command line.
If you see anything that might be causing this problem, please let me know.
#! /usr/bin/perl
use XML::Simple;
use CGI ":standard";
$query = "when=Mar&otherWhen=ignore&talks=history&otherTalks=ignore&active=teachers&otherActivities=ignore" .
"&rec=tours&otherRec=ignore&reimburse=full&WhyNot=busy&otherWhyNot=ignore&comments=";
$data = new XML::Simple(KeyAttr => {question => 'name', a => 'name'})->XMLin('survey.xml');
#Parses the query string and updates the hash.
foreach $pair ( split('&', $query) )
{
($q, $a) = split('=', $pair);
next if $a eq "ignore";
if ($q =~ /^other|comments/)
{
open (other, ">>$q.txt");
print other $a, "\n\n";
}
else
{
$data->{question}->{$q}->{a}->{$a}->{content}++;
}
}
$data->{total}++;
#Outputs the page.
print header(-type=>'text/html');
print start_html;
print h1("Survey Successful!!"), "\n";
print end_html, "\n";
#Outputs to the file.
$output = new XML::Simple(RootName => 'maa_survey')->XMLout($data);
open (out, ">survey.xml");
print out $output;
close(out);
And yes, all the file IO works.