Disable functionality thru commenting out a use

R

Robert Nicholson

I want to disable some functionality by making it conditional that it's
use statement is in the script.

How in general can you tell if a module is present or loaded? if
defined(X) what should X be?

I want to disable some features in a big perl script by
conditionalizing the code that relies on those modules and be able to
disable those features by comment out the "use" line for the modules.
 
M

Mumia W. (on aioe)

I want to disable some functionality by making it conditional that it's
use statement is in the script.

How in general can you tell if a module is present or loaded? if
defined(X) what should X be?

I want to disable some features in a big perl script by
conditionalizing the code that relies on those modules and be able to
disable those features by comment out the "use" line for the modules.

Here's one way:

use Data::Dumper;

my @watergate = qw(Haldeman Nixon Colson Dean);

if ($INC{'Data/Dumper.pm'}) {
print Dumper(\@watergate);
}
 
B

Brian McCauley

I want to disable some functionality by making it conditional that it's
use statement is in the script.

How in general can you tell if a module is present or loaded? if
defined(X) what should X be?

%My::Module::

(Note the trailing double colon).

Actually you don't need the defined() although if probably faster to
include it.

What this actually tells you is if the My::Module namespace contains
any symbols which is not always quite the same thing as you'd get by
cheking $INC{'My/Module.pm'} (as suggested by Mumia) which is the more
literal answer to your question as to whether the module has been
loaded.
I want to disable some features in a big perl script by
conditionalizing the code that relies on those modules and be able to
disable those features by comment out the "use" line for the modules.

I hope these are your own modules. Otherwise there's always a risk that
they may get unexpected use()d by another module and suddenly your
scripts functionality will change.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top