⭐ in reply to Defining a subroutine one of two ways depending on whether a package exists
Use the %INC hash (see perlvar). You need to look for a filename, though, not the package name:
eval { use Compress::Zlib; } # ... much other code, or in some other module... BEGIN { *myCRC = (exists $INC{'Compress/Zlib.pm'}) ? sub { crc32(@_) } : sub { 0 }; }
|
|---|