Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Testing for a module's presence

by rlb3 (Deacon)
on Feb 05, 2005 at 21:44 UTC ( [id://428414]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Testing for a module's presence

Hello,
I think you would have to do something like:
eval { require Some::Module; }; if ($@) { print "Can't find Some::Module\n"; }

When you say "use", things happen at compile time and would happen before the eval so, the error would not get trapped.

rlb3

Replies are listed 'Best First'.
Re^2: Testing for a module's presence
by sandfly (Beadle) on Feb 11, 2005 at 18:09 UTC
    "require" also better because it doesn't call import(). The module code still gets executed though. Typically, "require"d modules just create subs in their own package, but a badly-behaved module could in principle mess up any namespace.

    If you want to "use" a module at runtime, you can eval a quoted string:
    eval "use $mymodule";<br>print $@ if $@;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://428414]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.