http://www.perlmonks.org?node_id=1061782


in reply to To DEBUG, or to COMMENT. _That_ is the question

I have always wished for ... and, this being Perl so I’m sure it must exist I just don’t know of it ... an #if .. preprocessor capability, a la C/C++.   I would like “true conditional-compilation,” for any purpose including but not limited to the insertion of debugging code.   I am not familiar with this particular module enough to comment on its merits.   Certainly, these messaging techniques are crucial to the successful debugging and maintenance of production code ... whether done in this particular way or not.   Thanks for pointing out this module ... it seems well worth a closer look.

Replies are listed 'Best First'.
Re^2: To DEBUG, or to COMMENT. _That_ is the question
by chromatic (Archbishop) on Nov 08, 2013 at 22:42 UTC

    How about the -P flag, as documented in perlrun (with a huge list of caveats)?

      The -P command-line switch was deprecated in perl version 5.10.0 and removed as of version 5.12.0 (see perl5120delta). But the equivalent behaviour is provided by the module Filter::cpp:

      #! perl use strict; use warnings; use Filter::cpp; #define DEBUG #define XYZ 42 #ifdef DEBUG print "Debugging enabled\n"; #else print "Debugging disabled\n"; #endif print XYZ . "\n";

      Output:

      13:14 >perl 772_SoPW.pl Debugging enabled 42 13:14 >

      See perlfilter.

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

        You're right, of course. For some reason I had a terminal window open with a Perl 5.10.1 environment and chose that one to run perldoc instead of anything more recent.