Is the path to my flat-file text file wrong? Going from Linux to Windows server?

Use CGI::Carp qw(fatalsToBrowser) or die "Problems loading CGI. Pm" is your problem.

Up vote 0 down vote favorite share g+ share fb share tw.

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 " Thank you!

"; print "Thank You ". $custFirst. "\!

We appreciate your assistance. "; print "The following information has been recorded: Name: ". $custFirst.

" Gender: ". $custGender. " Division: ".

$custDiv. " Phone: ". $custPhone.

" Email: ". $custEmail. " How often do you use the internet?

: ". $custInternet. " How often do you visit the website?

: ". $custwww. " Are you familiar with demographic data?

: ". $custDemographic. " Do you have work experience in economics, business, or a related field?

: ". $custExperience. " Weekdays that you are available: ".

$custWeekdays. " "; print " "; 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. Perl cgi flat-file windows-server link|improve this question edited Apr 5 '11 at 23:31daxim19.5k21750 asked Apr 5 '11 at 20:09OneBigNewbie134 100% accept rate.

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.

Thanks, I'll use the portable version of Strawberry Perl to test my script. That should be fine since it doesn't require admin rights to install. My situation is a bit odd since I was never hired to do this (hence my limited capability and access to things like error logs).

It's just one of the things I have to contort myself into doing as an added job responsibility. Thanks! – OneBigNewbie Apr 11 '11 at 13:09.

You have the following lines: # Print the Header print $cgi->header(); and further down: #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"; Both do the same thing — you are printing the same content-type header twice.

You might remove one or the other print call. Also take a quick look through references to header() in the CGI. Pm docs to see the other things you can do.

Thanks, I think I added that during one of my attempts at debugging the code (one site mentioned that if a header isn't present then perl will output to the terminal). Though I tried removing one or the other and it still doesn't work. :( – OneBigNewbie Apr 5 '11 at 20:46 That's not true at all.

You can run the script on the command-line, and you simply get the header sent to standard output, along with everything else. The header is just text. Try troubleshooting by splitting up your script into smaller pieces, until you get something that works.

Then add pieces of your script back in, and re-run until you find the source of trouble. – Alex Reynolds Apr 5 '11 at 20:59.

There are several good resources on how to debug CGI. Pm scripts from the command line: perldoc.perl.org/CGI.html#DEBUGGING perlmonks.org/?node_id=667813 oreilly.com/openbook/cgi/ch12_01.html How can I send POST and GET data to a Perl CGI script via the command line? I suggest you take a look at these techniques.

Thanks, I don't have access to ActivePerl or StrawberryPerl at work (ah..the fun of working in restricted environments). I'll have to install it on my machines at home and try to debug it at home. Thanks for the links to the techniques!

– OneBigNewbie Apr 5 '11 at 20:49.

Also, as a rough stab in the dark: open (Datastore, '>>',"E:/intranet/sds/research/docs/data. Txt") or die "Can't open file: $! "; I'm not a Windows guy, but I think pathnames in Windows use backslashes, instead of the forward slashes that pretty much everyone else settled on using.

In addition to fixing the print call, you might also replace the pathname with: E:\intranet\sds\research\docs\data.txt.

2 Windows will generally accept either type of slash. There are exceptions, but there should be no problem opening a file. Couldn't hurt... except for having to do all the escaping.

– Schwern Apr 5 '11 at 22:23.

One other suggestion that probably doesn't have anything to do with the issue, but is just a matter of redundancy: #! C:\perl\bin\perl. Exe -w -t The -w flag is the same thing as: use warnings.

2 Not quite the same. Use warnings is lexical, it applies just to the scope it's in (in this case, the file). -w turns on warnings for the whole program: every function and library you use.

Doesn't hurt to turn on both. – Schwern Apr 5 '11 at 22:25.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions