I love Smart::Comments, use it a bunch. I got greedy and wanted to simply switch it on and off using a variable/optin whatnot.

Thing is , it's a 'source filter'- it does stuff to your code that changes the behaviour- pre compile. Very witty. So.. the following does not work:

#!/usr/bin/perl -w use strict; use Smart::Comments '###'; use Getopt::Std; my $o = {}; getopts('d', $o); ### smart comments are on unless ($o->{d}) { print STDERR 'debug is not on. no smart comments..'; no Smart::Comments; } ### i'd like this to output if -d is used

But of course every comment after no Smart::Comments; will not be parsed to output.

I tried an eval of 'no Smart::Comments' - but that must run before the whole script is compiled- so ... no cigar. I tried some variations of eval and require too.

I also tried a wasteful pre compile to set Smart::Comments to on- but it won't fly through to the rest of the script.

Any suggestions? This is mainly curiosity- seems like an interesting problem. Would there be a way to programmatically (that's a word?) turn off or on a source filter to the same calling source?- ach- head hurts :-)


In reply to Smart::Comments source filter on or off .. post compile? by leocharre

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.