Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

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

by andreas1234567 (Vicar)
on Feb 06, 2008 at 09:48 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-03-28 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found