I tried to check if XML::Simple is installed in my system or not.
perl -e 'while (<@INC>) { while (<$_/*.pm>) { print "$_\n"; } }'
The above one-liner was used for listing all modules installed in my system. However, it is not listing XML modules.
However, the following executes fine.
perl -e "use XML::Simple "
What might be the issue?
I believe your solution will only look in the root of each directory path contained in the @INC array. You need something recursive, like:
What you're doing there is not recursing into directories. It is only listing the modules in the root directory of the
@INC
directory.The module
XML::Simple
will live in one of the@INC
paths underXML/Simple.pm
.What he said above to find specific modules.
CPAN
explains how to find all modules here, see How to find installed modules.For example, to check if the DBI module is installed or not, use
You will see error if not installed. (from http://www.linuxask.com)
If you're running ActivePerl under Windows:
C:\>ppm query *
to get a list of all installed modulesC:\>ppm query XML-Simple
to check ifXML::Simple
is installedThis joins the paths in @INC together in a string, separated by spaces, then calls glob() on the string, which then iterates through the space-separated components (unless there are file-globbing meta-characters.)
This doesn't work so well if there are paths in @INC containing spaces, \, [], {}, *, ?, or ~, and there seems to be no reason to avoid the safe alternative:
Bravo for @user80168's solution (I'm still counting
\
's !) but to avoid all the escaping involved with aliases and shells:works reasonably well.
Here might be the simplest and most "modern" approach, using
Module::Runtime
:This will give a useful error if the module is not installed.
Using
-MModule::Runtime
requires it to be installed (it is not a core module).