I’d like to enable/disable the comments within my Perl program that make use of the module Smart::Comments. I’ve toyed with the idea of doing this by providing a –verbose switch as part of my list of command line options. When this switch is set, I was thinking of enabling the Smart::Comment module like so:
#!/usr/bin/perl
use Getopt::Long;
use Smart::Comments;
my $verbose = 0;
GetOptions ('verbose' => \$verbose);
if (! $verbose) {
eval "no Smart::Comments";
}
### verbose state: $verbose
However this doesn’t work for me. It seems to be something with the way Smart::Comments itself works, so I’m suspicious of the way in which I’m trying to disable the module with the eval “no …” bit. Can anyone offer me some guidance on this?
Take out the
use Smart::Commentsline out of the script, and run you script with or without the-MSmart::Commentsoption. Using the-M<module>option is like putting ause <module>statement at the beginning of your script.Also see the
$ENV{Smart_Comments}variable in theSmart::Commentsdocs.Here, you would use
Smart::Commentsin your script likeand then run
to run without smart comments, and
to run with smart comments.
Update The
Smart::Commentsmodule is a source filter. Trying to turn it on and off at runtime (e.g.,eval "no Smart::Comments") won’t work. At best, you can do some configuration at compile time (say, in aBEGIN{}block, before loadingSmart::Comments):