Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

A simple but good debug routine..

by spm (Acolyte)
on Jun 26, 2001 at 04:52 UTC ( [id://91500] : CUFP . print w/replies, xml ) Need Help??

I'm pretty sure most adiquitely skilled JAPHs know how to do this,
but I'm posting it here because I happen to like it, and others may to. When I'm coding I allways use this, so like:
sub debug { print shift if ($debug); }
... hope someone likes =)

Replies are listed 'Best First'.
Re: A simple but good debug routine..
by osfameron (Hermit) on Jun 26, 2001 at 17:22 UTC
    Useful, but with one slight modification,

    sub debug { print STDERR shift if ($debug); }

    it might turn out even more useful in the long run.

    This prints the debug text to Standard Error, which means that if you pipe the output of your script to a file or command, you will still see the warnings, but they won't appear in the final file.

    Cheerio!
    Osfameron

Re: A simple but good debug routine..
by mirod (Canon) on Sep 07, 2001 at 15:11 UTC

    OK, one last modification, print actually takes a list as argument, so you want to write your debug as:

    sub debug { print STDERR @_ if($debug); }

    so you can call it just like print:

    debug "foo: ", @foo, "\n";

    And actually I usually define DEBUG as a constant:

    use constant DEBUG => 1; # at the top of the code sub debug { print STDERR @_ if DEBUG; }