Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: I usually debug via...

by legato (Monk)
on Mar 03, 2005 at 00:04 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found