> -----Original Message-----
> From: Li, Jialin [mailto:[EMAIL PROTECTED]
> Sent: 26 September 2008 06:16
> To: aa aa
> Cc: [email protected]
> Subject: Re: send die "" to a file
>
> On Thu, Sep 25, 2008 at 11:55 PM, aa aa <[EMAIL PROTECTED]> wrote:
>
> >
> > Hi,
> >
> > I try to open several files, if one of them failed, my program will
die
> and
> > then send the died information to a file.
> >
> > eg.
> > open(AA, "a.txt") or die "can't open file a.txt\n";
> >
> > But I want to this string "can't open file a.txt\n" print to a file.
> >
> > Is anyone can help me?
> >
> > org.chen
You could call an error routine with your string as an argument,
or
or &Error("Could not pen the file a.txt" ;
Then in your Error sub you do what ever you want to do with that
error. I have used this and considered expanding it to include
error codes in warning/fatal ranges etc but have not yet felt the
need.
This is what mine does (The $log->msg liones are from Log::Simple.):
sub Error {
local ($errormessage) = @_;
if (defined $log) {
$log->msg(1,$errormessage);
}
print "\n\nERROR:\t" . $errormessage . "\n\n" ;
# rollback DB if it was connected
if (defined $dbh ) {
$rc = $dbh->rollback ;
}
if (defined $log) {
$log->msg(1,"Rollback:\t",$rc,"\n");
}
print "\nCalling cleanup to close connections and rollback
etc...\n" ;
Cleanup();
if ($SendEmailNotification) {
$subjmodifier= " - ERROR" ;
$EmailBody = $errormessage;
PrepEmailNotification($subjmodifier,$EmailBody,@FileList);
} else {
if (defined $log) {
$log->msg(1,"Email notification
disabled\n");
}
}
Perhaps a more experienced Perl Monger might comment on that approach
in general ?
Ta
Stu
Information in this email including any attachments may be privileged,
confidential and is intended exclusively for the addressee. The views expressed
may not be official policy, but the personal views of the originator. If you
have received it in error, please notify the sender by return e-mail and delete
it from your system. You should not reproduce, distribute, store, retransmit,
use or disclose its contents to anyone. Please note we reserve the right to
monitor all e-mail communication through our internal and external networks.
SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and
are used under licence. British Sky Broadcasting Limited (Registration No.
2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home
Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited
(Registration No. 2340150) are direct or indirect subsidiaries of British Sky
Broadcasting Group plc (Registration No. 2247735). All of the companies
mentioned in this paragraph are incorporated in England and Wales and share the
same registered office at Grant Way, Isleworth, Middlesex TW7 5QD.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/