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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|