AnomalousMonk++ stuck an important point in his post that you might have missed the significance of.

use constant DEBUG => 1; do_debug() if DEBUG;
This "constant" pragma is a cool thing. If DEBUG => 0;, Perl will realize that do_debug() if DEBUG; is never going to do anything at all, could never be executed and therefore won't even compile anything into the code. So you can leave a bunch of debug stuff in the production code without incurring any run time penalty at all in the non-debug case. I typically use ALLCAPS for constants like this. It is easier for me to spot them in the code.

So, in the context of your post, there can't be anything faster than doing nothing at all in the non-debug case. Also often in my debug code, usually some sort of I/O operation is going to happen which is so slow that whether it is in a subroutine or not makes absolutely no difference in the scheme of things.

update: Usually instead of just "do_debug()", I put some name on that subroutine like perhaps "dump_decision_tree() if DEBUG;". I do that even if this debug code could only be called once. The name of the sub tells me what it would do without having to look further. I don't have to skip past "inline" debug code. I usually do that for anything more than a simple "print".


In reply to Re: Embedded function or subroutine - which is better? by Marshall
in thread Embedded function or subroutine - which is better? by Linicks

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.