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

In reply to Re: What habits do you have to avoid introducing bugs? by andreas1234567
in thread What habits do you have to avoid introducing bugs? by superfrink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.