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.


HTMLBasix fully recommends Hostmonster as your host of choice.
Masses of space, transfer, great uptime. All for a VERY affordable price!

Internal Server Errors




Die statements

If your script opens files like this:

open (F, "myfile.txt");
@lines=<F>;
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";
@lines=<F>;
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 $!";
@lines=<F>;
close (F);

...it 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     
VisitorsPageviews
Total: 5,684,736 Total: 16,065,673
Today: 2,896 Today: 7,357
Yesterday: 3,851 Yesterday: 9,129
Past Month: 119,381 Past Month: 282,999

3,849 visitors in the last 24 hours
This page has been visited 1,599 times
There are currently 25 visitors online
click to see where
most people online at once:
89 visitors on 06/08/2009
   You beaut











This site is © HTML Basix 2003 - 2009