If this is in a module, i usually add a _debug key to my blessed hash and use a function with a name similar to dbg("Message"). All this function does is :
sub dbg { my ($self,$msg) = @_; return if (! $self->{_debug}); print STDERR "[DEBUG] : $msg\n"; }
And, a simple accessor method like :
sub debug { my ($self,$val) = @_; $self->{_debug} = $val if (defined $val); $self->{_debug}; }
While this all may seem a bit elaborate, it is excedingly useful to have as a standard for every module. If the $main::DEBUG is the approach you prefer, there is always more than one way to do it, and changing dbg to the following would work :
sub dbg { my $msg = shift; print "[DEBUG] : $msg\n" if ($main::DEBUG); }

OH, a sarcasm detector, that’s really useful

In reply to Re: Debugging in packages by MZSanford
in thread Debugging in packages by agoth

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.