I tried to check if XML::Simple is installed in my system or not.
perl -e \'while (<@INC>) { while (<$_/*.pm>) { print \"$_\\n\"; } }\'
Quick and dirty:
$ perl -MXML::Simple -e 1
For example, to check if the DBI module is installed or not, use
perl -e 'use DBI;'
You will see error if not installed. (from http://www.linuxask.com)
You can check for a module's installation path by:
perldoc -l XML::Simple
The problem with your one-liner is that, it is not recursively traversing directories/sub-directories. Hence, you get only pragmatic module names as output.
while (<@INC>)
This 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:
for (@INC)
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 under XML/Simple.pm
.
What he said above to find specific modules.
CPAN
explains how to find all modules here, see How to find installed modules.
If you want to quickly check if a module is installed (at least on Unix systems, with Bash as shell), add this to your .bashrc file:
alias modver="perl -e\"eval qq{use \\\$ARGV[0];\\\\\\\$v=\\\\\\\$\\\${ARGV[0]}::VERSION;};\ print\\\$@?qq{No module found\\n}:\\\$v?qq{Version \\\$v\\n}:qq{Found.\\n};\"\$1"
Then you can:
=> modver XML::Simple
No module found
=> modver DBI
Version 1.607