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