Howdy all --

In response to an article I read in Sys Admin Magazine (a damn good publication, for anyone out there who hasn't found it yet) I've been trying to create a template perl script that has all the functionality I usually want in a production-grade script that I can use to rollout new scripts much faster. I'm just about done, but I'm having some difficulty trying to discover if my script is ending out with errors or not. I've got an END block that defines what to do when everything is done, or if the script happens to die unexpectedly. Here's what I have for this check at the end:

Code:
if(($!) || ($?))  {
  my $mesg = "Internal Failures:\n------------------\n$!\n\n" .
    "External Failures:\n-----------------\n$?\n"; 
  &mail_errors($mesg);
}
I'm really just checking to see if the $! or the $? variables contain anything (and if they do, create a mail message, and send it out), but I'm discovering that the $! variable seems to ALWAYS contain something. Does anyone know of a better way to see if a perl script is ending gracefully or not?