[Purdue-pm] testing if a module is installed
Mark Senn
mark at purdue.edu
Mon Jun 23 12:43:25 PDT 2014
I was asked how to test if a module is installed and thought you might
be interested in the answer I gave.
In bash,
echo -n `perl -MGetopt::Missing -e 'print "y\n"' 2> /dev/null`
doesn't print anything,
echo -n `perl -MGetopt::Long -e 'print "y\n"' 2> /dev/null`
rints "y".
Or,
perl -MGetopt::Name -e 1
prints an error message if module is not installed,
or nothing if it is installed.
Or, in Perl
if (eval 'require Getopt::Long') { print "yes"; }
prints "yes" if the module exists and doesn't do anything otherwise.
Perl has a ExtUtils::Installed module to test if a module has been
installed but I don't know if that module is alwayso guaranteed to
be installed, and what version of Perl it was first available for.
-mark
More information about the Purdue-pm
mailing list