Tuesday, August 18, 2009

Perl : Finding Installed Modules in Perl

Context:
I was working on a solution to upload data from an excel file - that contains macros - using Perl. Perl is a module based implementation of parsing langugage and has a different module used for Windows / Linux based implementation for parsing / creating excel files (Win32::OLE->GetActiveObject('Excel.Application') viz. Spreadsheet::ParseExcel )

Perl file would work on Windows environment but not on Linux. I will not get into the details what the error message I got and what does it means for now.

Commands to list Perl modules:
After a while of googling - I figured out following one line script that will list all the Perl modules installed on Linux environment.

perl -MFile::Find=find -MFile::Spec::Functions -lwe 'find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC'

here is the same command to for Windows:
perl -MFile::Find=find -MFile::Spec::Functions -lwe find { wanted => sub { print canonpath $_ if /\.pm\z/ }, no_chdir => 1 }, @INC
Nothing much has changed other than double quotes highlighted in red.

An Alternate Way:
One can also try executing following command to fetch the details. If there is an error while execuing command, it means the module is not installed.

perl -MSample::Module -e 'print "\nModule is Installed\n\n"'

sample output - installed module:
bash-3.2$ perl -MExtUtils::Installed -e 'print "\nModule is Installed\n\n"'
Module is Installed
bash-3.2$


Sample output - module that is not installed:
bash-3.2$ perl -MSpreadsheet::ParseExcel -e 'print "\nModule is Installed\n\n"'
Can't locate Spreadsheet/ParseExcel.pm in @INC (@INC contains: /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi ... /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi /usr/lib/perl5/5.8.8 .).
BEGIN failed--compilation aborted.
bash-3.2$

Hope this helps . . .

No comments:

Post a Comment