Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: debugging /logging help

by quidity (Pilgrim)
on Dec 07, 2000 at 00:31 UTC ( [id://45309]=note: print w/replies, xml ) Need Help??


in reply to debugging /logging help

It is said that the best debugging aid is a set of liberally sprinkled print statements and some careful logical thought.

I find it useful to give most of my larger programs a 'verbose' mode which prints out progress indication, time spent, contents of data structures and whatnot. The easiest way of doing so is to have a sub:

sub debug_info { print join ':', "\n*", @_; print "\n"; return 1; }

then throughout the program have lines like:

debug_info('plotting world domination',$foo, $bar) if $verbose;

I usually make a command line option for verbosity with something like:

my $verbose = $ARGV[0] || 0;

Replies are listed 'Best First'.
Re: Re: debugging /logging help
by marius (Hermit) on Dec 07, 2000 at 00:56 UTC
    why not check your if $verbose value within your subroutine? That way you spend less time sprinkling "if $verbose" throughout your program.. Granted, my method is slightly less effecient, but you could change your sub to:
    sub debug_info { return(0) unless $verbose; print join ':', "\n*", @_; print "\n"; return 1; }


    -marius

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2024-04-18 15:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found