Help with my perl, how to send email when sees error

From: Mike F <u518615722_at_spawnkill.ip-mobilphone.net>
Date: Tue, 25 Sep 2001 19:37:44 GMT
Message-ID: <l.1001446664.1235595703_at_[64.94.198.252]>



Hi, Folks
I have a perl scripts like this:

[Quoted] sub trap_die
{

   my _at_param = @_;

$message = $param[0];
$CommandString = "/bin/mailx -s \"$message\" xxxx\_at_yyyy.com ";
      system ( $CommandString );
}
use strict;
use DBI;

my $dbh = DBI->connect ( 'dbi:Oracle:test',

                        'system',
                        'manager',
                        {
                                 PrintError => 0,
                                 RaiseError => 1,
                                 AutoCommit => 1
                        }
                        ) || die "Database Connection not made 
$DBI::errstr" ;
my $sql = qq{ select * from global_name} my $sth = $dbh ->prepare($sql);
$sth->execute();
       while (my _at_rows = $sth->fetchrow_array) {
       print "_at_rows[0]\n";
                                                }
$sth->finish();

$dbh->disconnect();

For any reason there is an error, perl will exit. Everyday I have to read output files to see whether there is an error, how can I make a perl call my sub function TRAP_DIE so that when error, I will get an email?
I tried to put the line

if ($dbh->error) {trap_die("error");}
but it will not work because the perl will exit as soon as it raise error.

Thanks for your help.  

-- 
Sent by dbadba62 from hotmail  in area  com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new
Received on Tue Sep 25 2001 - 21:37:44 CEST

Original text of this message