PERL CGI Tutorial
for Writing Interactive Form Scripts

Troubleshooting Scripts

Things to Check

1. Shebang Line
2. File Permissions
3. Action attribute
4. Errors in code.

On the Local Server

File Not Found Error 404
This error will occur on and off line when you do not supply a correct path to a document or if the file does not exist. The error usually occurs when you call a script from the action attribute on a form. If the calling form is written in HTML and resides in the html directory you must include the cgi-bin\ path information for the script.
Example: action="cgi-bin/confirm.pl"

When you look at the error recorded in the error log file, notice that the browser was trying to find the script in the htdocs/ directory. This error was produced using the action statement
action="confirm.pl"
in the orderform.html document.
See code below:
[error] [client 127.0.0.1] (2)No such file or directory: script not found or unable to stat: c:/usr/htdocs/confirm.pl

When you get this error (HTTP 404)look at the URL on the top blue bar of the Browser beside Browser Menu. This will tell you where the browser is looking for the script or HTML document.

When calling a script with a script, exclude the path information if both scripts reside in the cgi-bin directory.

This error was produced by using the action statement on the confirm.pl script: action ="cgi-bin/checkout.pl"
[error] [client 127.0.0.1] (2)No such file or directory: script not found or unable to stat: c:/usr/cgi-bin/cgi-bin

Notice that the browser was looking for a second cgi-bin directory located within the c:/usr/cgi-bin directory.

Internal Server Error

Errors in your code can be diagnosed using the Error Log Files. The following error mesages were produced by reversing the curly bracket in the confirm.pl script, on the line that reads:
if ($value >0)}
Notice that Perl pin points the error, as syntax error at......line 38, near ")}"
Most errors will be a little harder to find than this one.
[Tue Apr 17 09:34:59 2001] [error] [client 127.0.0.1] Premature end of script headers: c:/usr/cgi-bin/confirm.pl
[Tue Apr 17 09:34:59 2001] [error] [client 127.0.0.1] syntax error at c:/usr/cgi-bin/confirm.pl line 38, near ")}"
[Tue Apr 17 09:34:59 2001] [error] [client 127.0.0.1] Unmatched right curly bracket at c:/usr/cgi-bin/confirm.pl line 46, at end of line
[Tue Apr 17 09:34:59 2001] [error] [client 127.0.0.1] (Might be a runaway multi-line << string starting on line 42)
[Tue Apr 17 09:34:59 2001] [error] [client 127.0.0.1] syntax error at c:/usr/cgi-bin/confirm.pl line 46, near "}"
[Tue Apr 17 09:34:59 2001] [error] [client 127.0.0.1] Execution of c:/usr/cgi-bin/confirm.pl aborted due to compilation errors.

Notice that the date and time are all the same for the one error.

This second error in code was created by leaving off the semi-colon on a line that reads:
print <<End_of_Body

[Tue Apr 17 10:03:21 2001] [error] [client 127.0.0.1] Premature end of script headers: c:/usr/cgi-bin/confirm.pl
[Tue Apr 17 10:03:21 2001] [error] [client 127.0.0.1] Scalar found where operator expected at c:/usr/cgi-bin/confirm.pl line 31, near "$price"
[Tue Apr 17 10:03:21 2001] [error] [client 127.0.0.1] (Missing semicolon on previous line?)
[Tue Apr 17 10:03:21 2001] [error] [client 127.0.0.1] syntax error at c:/usr/cgi-bin/confirm.pl line 31, near "$price"
[Tue Apr 17 10:03:21 2001] [error] [client 127.0.0.1] Execution of c:/usr/cgi-bin/confirm.pl aborted due to compilation errors.

Notice that Perl tells us it is a missing semi colon, but it is not quite sure where it is located.

Be sure to test all of your scripts before uploading them to your web site.

On Your Web Space

Internal Server Error
Many beginners get this message the first time they upload their scripts to their web space and try to execute them.
First check your file permission settings. (Set scripts to 755 using your FTP tool.)
See File Permissions

Next check the the shebang line on your scripts. The browser may not be able to find the location of Perl.exe on the server. If your scripts worked ok on your local server, and you get this message the first time you try to run them on the internet check your web host's documentation for the correct shebang line to place on your scripts.

If your web host allows you access to your error log messages, an improper shebang line will produce this message:
[error] [client 127.0.0.1] (2)No such file or directory: couldn't spawn child process: c:/usr/cgi-bin/confirm.pl
See Shebang Line

Values Not Passed

If values are not passed from the form to the processing script.
Some web host's configure their server to use either the GET or POST method and not both.
If you click the submit button and get a blank page or your values are not passed to the script, try using the opposite method.

Saving to a file Using the Split Function
CGI Online is a service provided by Net Success 2000 Plus.
PO Box 1508
Somerset, KY 42502
Last Modified: October 9, 2007

| HTML TOC | Website Design Workshop | Home |