in reply to debugging /logging help

One thing I've found useful in debugging is to use levels, e.g.:
my $debug = 11; ... print STDERR "something worked: $wombat\n" if $debug > 5; ... print STDERR "in here: too much detail", join ", ", @_, "\n" if $debug > 20;
etc. That way I can leave them in until production or later, and bump things back up when I break something. I try to make it a habit to always write debug noise in like that at the start (every "print STDERR ..." line has a debug level) and it works out much easier as the development progresses.

You could add something like that:

debugprint("now entering mysub ...\n", 11); sub debugprint($$) { my ($err_str, $debug_value) = @_; print $err_str if $debug_value >= $debug;
or something ...

a

Replies are listed 'Best First'.
Re: Re: debugging /logging help
by gharris (Beadle) on Dec 07, 2000 at 21:35 UTC
    I use an approach along these lines, but break the printing out into a sub...

    And I have a question to contribute:
    Is there a way to tell on what line your sub was called from? So that I could include the current line number in the sub:

    sub mydebug { $msg = shift; print STDERR 'Line '. $linethatcalledme .": $msg\n"; }
    I've been inactively looking for this for a while, almost to the point that I'm going to have to start looking for real =)

    --Glenn

      Here's a good place to look for real: caller. :)

      Not only can caller tell you where your sub was called from, it can tell you where the sub that called your sub was called from, and so on all the way back to the main code.

        Well, now I know why I couldn't find it! That's just too easy =)
        Thanks for the tip. That will be a real simple addition.

        --Glenn