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.

Recommended Answers

All 2 Replies

Hi,
Look for what 'error.log' says, logged by the web server to actually see what went wrong. You can find this file somewhere under directory tree of web server installation.

Also you can add

use warnings;
use CGI::Carp qw(fatalsToBrowser);

for making perl errors to appear on the browser.

kath.

Turns out the problem was the colons. Colons aren't allowed in file names.

Silly me....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.