http://www.perlmonks.org?node_id=666515


in reply to What habits do you have to avoid introducing bugs?

In addition to what's been already said, I'd use Log::Log4perl and Log::Dispatch::FileRotate to detect errors and enable fast and easy debugging by the flip of a flag (i.e. change log level):
$ cat 666463.pl use strict; use warnings; use Log::Log4perl; use Log::Dispatch::FileRotate; my $conf = q( log4perl.category.foo = DEBUG, FileRotateAppender log4perl.appender.FileRotateAppender = Log::Dispatch::File +Rotate log4perl.appender.FileRotateAppender.filename = foo.log log4perl.appender.FileRotateAppender.mode = append log4perl.appender.FileRotateAppender.size = 100000 log4perl.appender.FileRotateAppender.max = 5 log4perl.appender.FileRotateAppender.layout = PatternLayout log4perl.appender.FileRotateAppender.layout.ConversionPattern=[%p] % +d %M %F:%L:- %m%n ); Log::Log4perl::init( \$conf ); my $log = Log::Log4perl::get_logger("foo"); sub check_something { my $something = shift; $log->debug(qq{something:'$something'}) if $log->is_debug(); if (!defined($something)) { $log->error(qq{something is nothing!}) if $log->is_error(); } return $something; } # ------ main ------ check_something(q{hello}); check_something(); __END__
Run it:
$ perl 666463.pl Use of uninitialized value in concatenation (.) or string at 666463.pl + line 23.
Inspect log:
$ tail foo.log [DEBUG] 2008/02/06 10:45:00 main::check_something 666463.pl:23:- somet +hing:'hello' [DEBUG] 2008/02/06 10:45:00 main::check_something 666463.pl:23:- somet +hing:'' [ERROR] 2008/02/06 10:45:00 main::check_something 666463.pl:24:- somet +hing is nothing!
--
Andreas