in reply to Re: Re: Using Perl to launch another Perl script and generate error log if it fails
in thread Using Perl to launch another Perl script and generate error log if it fails

If you aren't using your STDERR for anything else, just redirect it to the file and the warnings will show up there. You can do that in your shell script with foo.pl 2>> errlog.txt, or in Perl with:

open STDERR, ">errlog.txt" or die "Whoa! I can't even log my errors: $!";

Otherwise, you'll want the __WARN__ pseudo-signal:

open ERRLOG, ">errlog.txt" or die; $SIG{__WARN__} = sub { my ($msg) = @_; $msg ||= q{Warning: something's wrong}; # Add the file and line number to $msg here # using the return values from caller(). print ERRLOG, $msg; };
See also warn and caller in perlfunc and %SIG in perlvar.

-- 
LP^>

  • Comment on Re: Re: Re: Using Perl to launch another Perl script and generate error log if it fails
  • Select or Download Code