Re: use of uninitialized value....
- From: DBSMITH@xxxxxxxxxxxxxx
- Date: Thu, 26 Jan 2006 13:50:10 -0500
snip
> my $ftp = Net::FTP->new($remotehost, Debug => 10)
> || do {print FTPLOG "\nCannot connect to $remotehost:
$!",
> mailme(); return};
snip
This is a bit off topic, but I can't look at code like this without
suggesting the following alternative:
near the top of your program say:
{
my $olddie = $SIG{__DIE__};
$SIG{__DIE__} = sub {
my $error = shift;
$olddie->{$error} if ref $olddie;
mailme($error);
#other error stuff here
};
}
Then for the rest of your program you can say
my $ftp = Net::FTP->new($remotehost, Debug => 10) or
die "Cannot connect to $remotehost: $!";
This allows you to have a complicated error procedure that is common
to anywhere you use die(). It also makes your code cleaner. If you
want the same functionality without the program ending you can assign
your error handler to $SIG{__WARN__} and use warn() instead.
*********************************************************************************************************************
*********************************************************************************************************************
I appreciate the suggestion, but if there is a problem I want the progam to
email then die. So I would replace
the || do lines in the ftp section
with a routine call to? :
my $olddie = $SIG{__DIE__};
$SIG{__DIE__} = sub {
my $error = shift;
$olddie->{$error} if ref $olddie;
mailme($error);
#other error stuff here
};
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
.
- Follow-Ups:
- Re: use of uninitialized value....
- From: Chas Owens
- Re: use of uninitialized value....
- References:
- Re: use of uninitialized value....
- From: Chas Owens
- Re: use of uninitialized value....
- Prev by Date: Re: Simple RegEx expresion
- Next by Date: Re: use of uninitialized value....
- Previous by thread: Re: use of uninitialized value....
- Next by thread: Re: use of uninitialized value....
- Index(es):
Relevant Pages
|