Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: What habits do you have to avoid introducing bugs?

by andreas1234567 (Vicar)
on Feb 06, 2008 at 09:48 UTC ( #666515=note: print w/ replies, xml ) Need Help??


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


Comment on Re: What habits do you have to avoid introducing bugs?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://666515]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2015-07-06 08:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (70 votes), past polls