Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: I usually debug via...

by legato (Monk)
on Mar 03, 2005 at 00:04 UTC ( #436041=note: print w/ replies, xml ) Need Help??


in reply to I usually debug via...

While I use ptkdb for tracing, I also use the indispensible Data::Dumper::Simple0. Combining the latter with a global $_DEBUG allows me to do this:

use strict; use warnings; #... blah if ($_DEBUG) { require Data::Dumper::Simple; Data::Dumper::Simple->import; } sub _explain (@_); # ... some code $record = $sth->fetchrow_arrayref; _explain $record; # ... some code sub _explain (@_) { return undef unless $_DEBUG; local $|=1; my @call = caller(1); print '#- in ',$call[3],' ',Dumper($_),"\n" for (@_); }
This results in:
#- in mySub $record = [ 'aUser', 'aPassword' ]

I usually use STDOUT so I can redirect to a log file if I wish, but sometimes I call out to a logger module, too. One of the advantages of this is that I can set $_DEBUG in-code or with a command-line option &c., thereby controlling the verbosity level on a per-run basis.


0: I use this instead of Data::Dumper simply because it automagically prints the actual name of the variable instead of $VAR1 and the like. It's possible to do that with the Data::Dumper module, too, but the ::Simple version does it anyhow, so why reinvent that wheel?

Anima Legato
.oO all things connect through the motion of the mind


Comment on Re: I usually debug via...
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-12-28 10:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (180 votes), past polls