<?xml version="1.0" encoding="windows-1252"?>
<node id="377228" title="Re: brian's Guide to Solving Any Perl Problem" created="2004-07-25 01:34:20" updated="2005-08-10 15:28:25">
<type id="11">
note</type>
<author id="190362">
ff</author>
<data>
<field name="doctext">
&lt;i&gt; The best debugger in the universe is &lt;code&gt;print&lt;/code&gt;. &lt;/i&gt;&lt;p&gt;
&lt;code&gt;
        print STDERR "The value is [$value]\n";
&lt;/code&gt;
&lt;p&gt;&lt;p&gt;
To which I'd add, while not earthshaking or original, that I like using &lt;code&gt;warn&lt;/code&gt; even more than &lt;code&gt;print STDERR&lt;/code&gt;.  Besides being shorter, the fact that it's different makes it easier to find such statements and comment out those lines when I'm through with them.&lt;p&gt;
More particularly, I put my debugging 'warn' messages at the start of a line.  Since most of my perl code has been indented a couple of tabs away from column 1, the fact that these statements are 'debug' type statements stands out.  And since I might want to reuse the same debugging statements from time to time, rather than erase them when I'm done, I just comment them out when I'm "through" with them.  This way, when I'm desparate later to know what's happening in some region, those previously written &lt;code&gt;warn&lt;/code&gt; statements are there, waiting to be uncommented.  And if I uncomment seven or eight of them (among the dozens/hundreds in my code :-), I can easily find them again to turn them off when I'm done with them by doing a vim search for them at the start of a line.  &lt;p&gt;
&lt;code&gt;/^warn&lt;/code&gt;&lt;p&gt;
Then repeat my search with &lt;code&gt;n&lt;/code&gt; and repeat my 'uncomment' with a dot.  Because these statements are at the start of a line, they can be found differently than the &lt;code&gt;warn&lt;/code&gt; statements that are in the clear and are SUPPOSED to fire when triggered by real problems.)&lt;p&gt;

I also find that including&lt;p&gt;
&lt;code&gt;use Carp qw(cluck);&lt;/code&gt;&lt;p&gt;
early in my program and using&lt;p&gt;
&lt;code&gt;cluck&lt;/code&gt;&lt;p&gt;
statements at the start of a line (a la &lt;code&gt;warn&lt;/code&gt;) helps me figure out just how a particular subroutine got invoked.</field>
<field name="root_node">
376075</field>
<field name="parent_node">
376075</field>
</data>
</node>
