This is just like the following "C" code:

bool debug = true; // I think bool is a new C keyword... if (debug) { #include <assert.h> #include "mydebugstuff.h" }
The difference is that in C, you can more easily tell what is compile-time and what is run-time based on that hashmark. In Perl, we have the BEGIN block, but most of our compile-time code is actually executed via use.

You're mixing compile-time and run-time code, then, so it doesn't actually work. Someone mentioned the if pragma - but it's not really needed here.

Simply remove the if's. There's nothing wrong with warnings being used at all times. There's also nothing really wrong with loading modules you don't need - slows down compilation, but not much. If's usage is better suited for modules that may not be there than debugging statements that do no harm if they're left in, IMO. Since Data::Dumper is always installed, it's pretty safe to always load.

That said, if you want to avoid loading Data::Dumper, you can learn how to use require - then you will only load it when you need it - at runtime, not compile-time.


In reply to Re: syntax question: conditional 'use' statement? by Tanktalus
in thread syntax question: conditional 'use' statement? by Anonymous Monk

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.