HTML Basix - HTML tutorials and online webmaster tools

Htaccess code generators Code generators Tutorials

Online and offline code generators

Subscribe to RSS feed
Subscribe to the HTML Basix RSS feed.

Internal Server Errors

Die statements

If your script opens files like this:

open (F, "myfile.txt");
close (F);

then you need to do something about it! If at any stage the script can't open the file, this can lead to problems. Either a script can sit there hanging if it can't open and write to a file, or you can spend ages trying to work out exactly why your script isn't doing what it should be.

Change the above code to:

open (F, "myfile.txt") || die "cannot open myfile.txt";
close (F);

The script will then error with the message:

cannot open myfile.txt at test.cgi line 31.

If you use '$!' in your statement:

open (F, "myfile.txt") || die "cannot open myfile.txt $!";
close (F); will print out why it died

cannot open myfile.txt No such file or directory at test.cgi line 31.

$! contains the error returned by the server and you use it in your die statement to print the error out.

Use the same die statement with sendmail as well - if there's problems, it will stop the script hanging and return the error.

open(MAIL, "| /usr/bin/sendmail -t") || die "Unable to open sendmail. $!";

If there's a problem with sendmail, or the path to sendmail is wrong - it will end the script and return the error:

Unable to open sendmail. No such file or directory at test.cgi line 311.

It is recommended that you go right through your script and put 'die' statements in wherever the script tries to open up a file. It does two things: lets you know that there's a problem, as well as killing off the execution of the script instead of letting it keep trying forever to open a file that doesn't exist.

<< other errors Let's wrap it up >>

Site Stats     
Total: 9,637,833 Total: 27,994,846
Today: 338 Today: 1,357
Yesterday: 500 Yesterday: 1,674
Past Month: 15,500 Past Month: 51,894

552 visitors in the last 24 hours
This page has been visited 5,351 times
There are currently 4 visitors online
click to see where
most people online at once:
286 visitors on 06/27/2012
   You beaut

This site is © HTML Basix 2003 - 2009