On 8/30/07, Beginner <[EMAIL PROTECTED]> wrote: > On 30 Aug 2007 at 6:32, Peter Scott wrote: > > > On Thu, 30 Aug 2007 10:32:01 +0100, Beginner wrote: > > > I want all the output plus any error messages to got to a log file. I > > > used the BEGIN block to direct STDERR into the file: > > > > > > BEGIN { > > > open(STDERR, ">>/usr/local/myreports/report.log") || die "Can't > > > write to file: $!\n"; > > > } > > > > > > use strict; > > > use warnings; > > > ... > > > ### Start some logging ### > > > my $log; > > > my $logfile = "$dist_dir/report.log"; > > > open($log,">>$logfile") || die "Can't write to $logfile: $!\n"; > > > print $log "$0 called at ", &tm," with pid $$\n"; > > > > Why are you using a BEGIN block? Why not just make it the first > > executable statement? Do you have any other 'use' statements in the > > program? > > Yes I do. Several standard modules plus one or 2 of my own. The BEGIN > block adds the path to my modules as well so it really looks like > this at the moment (I have tested Mumia's INIT yet): > > BEGIN { unshift @INC, '/etc/perl';
This is better done with use lib qw(/etc/perl); which doesn't need the surrounding "BEGIN" block. > $| = 1; > open(STDERR, ">>/usr/local/myreports/report.log") || die > "Can't write to file: $!\n"; > } > > use MY::MakePDF; > use MY::SendEmail; > use MY::Number; > use MY::PDF_Handler; > use File::Basename; > use strict; > use warnings; > > I want the STDERR from those modules to go to the log file also. Just perfect ;-) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/