I don't use the debugger, I prefer the "print lots of checkpoints" debugging method. But simple print calls are insufficient. This method can be included in your MyUtils module, or whatever, and called from all your packages. It only prints the messages if the $YourPackage::DEBUG is >= the debug level that debug() is called with. prints the calling package, too. It supports being called as a class method or object method, too, so try stuffing it in @ISA and then you can Class->debug() or $obj->debug().
package MyUtil; use strict; use warnings; our $DEBUG = 0; # this is the default debug level if you don't set $Yo +urPackage::DEBUG sub debug { my ( $level, $caller, $time, $debug, @message, ); return $DEBUG unless @_; $caller = (ref $_[0]) ? ref shift : ($_[0] eq __PACKAGE__) ? shift + : (caller)[0]; $debug = exists $::{$caller}{DEBUG} ? ${$::{$caller}{DEBUG}} : $D +EBUG || 0; if ( $_[0] =~ /^\d+$/ ) { $level = shift; } else { $level = 1; } return undef if $debug < $level; @message = @_; return undef unless @message; $time = localtime; # I like the long time format because my STDERR + is usually a logfile. If you change this, change the spacing on the +second printf, too. printf STDERR "DEBUG (%s)(%3i)(%s): %s\n", $caller, $level, $time, + shift @message; while ( my $line = shift @message ) { printf STDERR "DEBUG".( ' ' x (34+length $caller) ).": %s\n", +$line; } return 1; } # and then somewhere else package main; our $DEBUG = 50; use MyUtil 'debug'; debug( 49, "Hello World! it's me, process $$", "And me, another line." + ); debug( 51, "Change the debug level for this one to print" ); __END__ DEBUG (main)( 49)(Sun Nov 14 14:28:34 2004): Hello World! its me, proc +ess 24665 DEBUG : And me, another line

In reply to Informative debugging messages and debug levels by Aighearach

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.