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

From: Ron Reidy <ron_at_indra.com>
Date: Tue, 25 Sep 2001 16:57:12 -0600
Message-ID: <3BB10BC8.F9511C99_at_indra.com>


Mike F wrote:
>
> Hi, Folks
> I have a perl scripts like this:
> ------------------------------------------------------
> 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
You are not trapping errors correctly. See the DBI docs for use of RaiseError and how it works.

-- 
Ron Reidy
Oracle DBA
Reidy Consulting, L.L.C.
Received on Wed Sep 26 2001 - 00:57:12 CEST

Original text of this message