in reply to how i capture a script error to a file ?
The error is not passed as an argument to your die handler, but is in $@.
Why shell out just to print an error message?
my $message = $@; if( open my $log, '>>', 'log.err' ) { print $log $message; } else { warn "Couldn't write to 'log.err': $!"; warn $message; };
Also, your __DIE__ handler will also be invoked from within eval { ... } blocks, which is most likely only confusing to you. You should check $^S to see if eval is currently running:
return if $^S; # we are within an eval block
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how i capture a script error to a file ?
by shmem (Chancellor) on Apr 27, 2017 at 13:16 UTC | |
by gabrielsousa (Sexton) on Apr 27, 2017 at 13:31 UTC | |
by shmem (Chancellor) on Apr 27, 2017 at 13:35 UTC |