pa...@compugenic.com wrote: > On Wed, Jun 24, 2009 at 09:41:10PM +0400, Roman Makurin wrote: >> On Wed, Jun 24, 2009 at 09:25:05AM -0700, pa...@compugenic.com wrote: >> > I'd like to automatically have my script's errors and warnings sent to >> > both STDOUT (console) and a log file. What is the proper way of doing >> this? >> >> print STDERR mess; >> print FILEHANDLE mess; >> > > STDERR is where errors go. Error messages are generated as a result of > an error, not a 'print' statement. Athough I could manually print to > STDERR, I'm trying to log all errors to both a logfile and STDERR. > > How can I do that? > --- There are several ways to do this, but I think the one you're looking for is to write custom handlers for $SIG{__WARN__} and $SIG{__DIE__}.
Here's a link to an example. http://www.cs.cf.ac.uk/Dave/PERL/node116.html In your case the handlers would open a filehandle to your log file and optionally use IO::Tee to send the output to that filehandle as well as STDOUT. http://search.cpan.org/~kenshan/IO-Tee-0.64/Tee.pm -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/