I used to do exactly the same as come of the comments here suggested: print statements, data dumper, and so on

Now I'm going 'agile' by including unit tests from the beginning of my coding, even if inheriting code from others.

In fact, I write tests first, then start coding to make them work. It's a different approach. My 'debugging' time decreased in the end because I was able to find many more mistakes early on.

Give it a try, google on unit testing. There's even a book on Extreme Perl and Test-Driver Design

An example: a simple accumulator. I start with writing Add.t first (the code at the end) and fill up Add.pm (first code on top) to make Add.t run without failures...


A simple accumulator
package Add; use strict; use warnings; sub new { my $class = shift; my $self = { ACC => undef, }; my $closure = sub { my $field = shift; if (@_) { $self->{$field} = shift; } return $self->{$field}; }; bless ($closure,$class); return $closure; } sub acc { &{ $_[0] }("ACC", @_[1 .. $#_]) } sub add { acc( $_[0],acc( $_[0] )+@_[1 .. $#_] ); } 1;
The test code
use strict; use warnings; use Test::More tests => 7; BEGIN { use_ok('Add'); } ok(my $a = Add->new(),"creation of accumulator"); ok($a->acc(3),"accumulator set to 3"); isnt($a->acc,0,"check if accumulator isn't zero"); is($a->acc,3,"check accumulator equals 3"); ok($a->add(3),"add 3 to accumulator"); is($a->acc,6,"check if add equals 6");

In reply to Re: debugging - straw poll ... by gargle
in thread debugging - straw poll ... by danmcb

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.