Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

RE: Checking to see if a particular Module is installed

by athomason (Curate)
on Aug 11, 2000 at 07:11 UTC ( [id://27449]=note: print w/replies, xml ) Need Help??


in reply to Checking to see if a particular Module is installed

punkkid's answer is close, but doesn't quite do it if the use statement doesn't return a true value. For example, perl -e "eval 'use CGI' or die" dies. The correct way would be
my $package = "GD"; eval "use $package; 1" ? gd_stuff() : alternate_stuff();

Replies are listed 'Best First'.
RE: RE: Checking to see if a particular Module is installed
by merlyn (Sage) on Aug 11, 2000 at 15:23 UTC
    Slightly simpler:
    eval 'require GD'; if ($@) { # problems with GD, fall back to non-GD } else { # we have GD, go for it! }
    There's no point in using use, because you can't affect the compile-time imports at runtime if it's not there!

    -- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://27449]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2024-04-24 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found