2008/9/26 aa aa <[EMAIL PROTECTED]>:
>
> 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.
>

Can use an "eval" as Randal suggested.
You could also redefined the DIE handler, as:

$SIG{__DIE__}=\&log_die;
sub log_die {
    my $time=scalar localtime;
    open (HDW,">>",$err_log);
    print HDW $time,"  ",@_;
    close HDW;
    die @_;
}

Then use die as usually in the scripts.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to