I'm a Perl newbie. I'm trying to learn based on a previous person's work and books such as Learning Perl and Modern Perl. I'm trying to update this script that interprets data from a HTML form and writes it into a text file since there is interest in our lab in getting this up and running again. The original script was written for use on a Linux server but we've since switched from Linux to Windows server.
The server that I do not have admin access to see the error messages is a Windows server with ActivePerl. I'm having difficulty figuring out the Windows equivalent path to tell the Perl script where to write the information. From talking to the admin it seems that our intranet is mapped on the E:
drive, although this may not be the fatal error.
When I attempt to run this script in the browser after the data has been entered on a form it just returns a generic:
CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers.
Any tips, documentation, tutorials are appreciated. Thank you.
#!C:\perl\bin\perl.exe -w -t
# Good programming practice dictates...
use strict;
use warnings;
# CGI.pm -- makes life easy
#Carp qw(fatalsToBrowser); outputs the error messages to the browser since there is no terminal to output error messages to. Should be removed before script is used in production.
use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";
# Initialize the CGI Interface
my($cgi) = new CGI;
# Print the Header
print $cgi->header();
#The dbmopen call is now de-appreciated. IE: it no longer works
#Kept for archival reasons
#if (! dbmopen(%DB, "/vol/research/docs/old_site_files/eyesignup/data/eyesignup_NEW.dat", 0666))
# {
# print "Error -- Cannot open database.\n";
# exit;
# }
# Tie is the correct way to do it now. But first we are going to experiment with writing to a flat .txt file.
open (Datastore, '>>',"E:/intranet/sds/research/docs/data.txt") or die "Can't open file: $!";
# Store variables and increment access count for this user
# So param('VARIABLE') is the name of the variables used in the HTML form while $custVARIABLE is the input for the database
my($custFirst) = $cgi->param('firstname');
my($custLast) = $cgi->param('lastname');
my($custGender) = $cgi->param('gender');
my($custAge) = $cgi->param('age');
my($custDiv) = $cgi->param('division');
my($custPhone) = $cgi->param('phone');
my($custEmail) = $cgi->param('email');
my($custEmployee) = $cgi->param('employee');
my($custInternet) = $cgi->param('internet');
my($custwww) = $cgi->param('www');
my($custDemographic) = $cgi->param('demographic');
my($custProjects) = $cgi->param('projectsworked');
my($custExperience) = $cgi->param('experience');
my($custWeekdays) = $cgi->param('Weekdays');
#Kept for archival reasons
#my($custName) = $cgi->param('name');
#my($custGender) = $cgi->param('gender');
#my($custDiv) = $cgi->param('division');
#my($custPhone) = $cgi->param('phone');
#my($custEmail) = $cgi->param('email');
#my($custInternet) = $cgi->param('internet');
#my($custwww) = $cgi->param('www');
#my($custDemographic) = $cgi->param('demographic');
#my($custExperience) = $cgi->param('experience');
#my($custTimes) = $cgi->param('times');
#my($custStudies) = $cgi->param('studies');
#$custTimes =~ s/\r\n/~/g;
#This takes the input and places it into an array, starting with the individual's
@InfoDB = $custFirst."|".$custLast."|".$custGender."|".$custAge."|".$custDiv."|".$custPhone."|".$custEmail."|".$custEmployee."|".$custInternet."|".$custwww."|".$custDemographic."|".$custProjects."|".$custExperience."|".$custWeekdays;
print Datastore (@InfoDB);
print "\n";
#Kept for archivival reasons.
#$DB{$custName} = $custGender."|".$custDiv."|".$custPhone."|".$custEmail."|".$custInternet."|".$custwww."|".$custDemographic."|".$custExperience."|".$custTimes."|".$custStudies;
#Kept for archival reasons. dbmclose is de-appreciated
#dbmclose(%DB);
#Instead use untie. But first we're just going experiment with using a flat storage system.
#untie(%DB);
close (Datastore) or die;
#Now inform the person their data has been saved. This is terribly ancient code so I haven't gotten around to fixing this part yet.
print "Content-type: text/html\n\n";
print "<HTML>
<HEAD>
<TITLE>Thank you!</TITLE>
</HEAD>
<BODY>";
print "<H1><U>Thank You ".$custFirst."\!</U></H1>
<P>We appreciate your assistance.</P>
<HR width=\"75%\">";
print "<P><H3>The following information has been recorded:</H3>
Name: <I>".$custFirst."</I></p><P>
Gender: <i>".$custGender."</i></p><p>
Division: <i>".$custDiv."</i></p><p>
Phone: <i>".$custPhone."</i></p><p>
Email: <i>".$custEmail."</I></p><P>
How often do you use the internet?: <i>".$custInternet."</i></p><p>
How often do you visit the website?: <i>".$custwww."</i></p><p>
Are you familiar with demographic data?: <i>".$custDemographic."</i></p><p>
Do you have work experience in economics, business, or a related field?: <i>".$custExperience."</i></p><p>
Weekdays that you are available: <i>".$custWeekdays."</i></p><p>
";
print "
</BODY>
</HTML>";
I've made a few changes to compensate for some of the limitations I am working in. For example, temporarily outputting errors to the browser until I get this working. And moving from the old dbmopen
call (which is no longer working) to a flat file storage.
use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";
is your problem.
$ perl -wle 'use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI.pm";'
syntax error at -e line 1, near "qw(fatalsToBrowser) or"
Execution of -e aborted due to compilation errors.
Your program was dying as it was compiling, so you got no useful syntax error. Normally you'd be able to see this in your logs, but you can't. The or die
is unnecessary (and a syntax error) on a use
statement. It will already throw an error.
You really, really need a copy of Perl on your local machine at work to test your programs. Use this as ammunition. If they still won't let you have the tools to work, use the portable version of Strawberry Perl that requires no installer.
You also need access to your error logs. Ask the admins for that. It's possible they can give you access to just your logs without giving you full access to the server.