Reputation: 6891
I have some rarely used code in my perl script that requires a module that is not installed by default (but it is a standard cpan deployed module).
Is there a way to optionally load a module if available and just disable some functionality if not available to make the script run on most default perl distributions if not this special functionality is needed?
Upvotes: 3
Views: 318
Reputation: 2331
you can use a try-catch block (called "eval" in Perl) while requiring this module.
e.g:
my $zlib_available=0;
eval
{
require Compress::Zlib;
$zlib_available=1;
};
and later on:
if ($zlib_available) {
$page = Compress::Zlib::memGzip($page);
}
Upvotes: 6