1

How do I check if Spreadsheet::WriteExcel is available in my Perl ?

I ran

  perldoc -v Spreadsheet::WriteExcel 

and got the following output which suggests no Spreadsheet::WriteExcel on my perl

/usr/local/bin/perldoc => Pod::Perldoc v3.13

Formatter class Pod::Perldoc::ToMan successfully loaded!
Will format with the class Pod::Perldoc::ToMan
Searching for Spreadsheet::WriteExcel
Looking for Spreadsheet/WriteExcel in /opt/SYSperl/bin /opt/SYSperl/lib/5.8.6/sun4-solaris /opt/SYSperl/lib/5.8.6 /opt/SYSperl/lib/site_perl/5.8.6/sun4-solaris /opt/SYSperl/lib/site_perl/5.8.6 /opt/SYSperl/lib/site_perl . /opt/pgti/ixp/bin /opt/pgti/ixp/bin /opt/pgti/ixp/bin /opt/CA/uajm/elp/autosys/bin /usr/openwin/bin /usr/bin /usr/ccs/bin /usr/local/bin /opt/RFMadmin/exe /opt/RFMadmin/bin . /apps/risk/bin
No documentation found for "Spreadsheet::WriteExcel".

But I saw a code using below line and other functions , working fine on my system

$workbook = Spreadsheet::WriteExcel->new($file);`enter code here`
Vicky
  • 1,298
  • 1
  • 16
  • 33
  • 1
    The easiest way to check if something is installed is to run `$ perl -MSpreadsheet::WriteExcel\ 999`. It will either complain that it can't load it, or complain that it cannot load version 999, and tell you which version it has instead. Note the blank space after the backslash. – simbabque Aug 04 '17 at 15:18
  • I'm pretty sure I've seen modules with `VERSION` numbers as some form of a date, similar to '2016_12_04', which wouldn't complain. I use the method you mentioned above but with a bunch more 9s. – jmcneirney Aug 04 '17 at 15:49
  • 1
    @SinanÜnür true, that would save one ugly character. :) – simbabque Aug 04 '17 at 16:41
  • @SinanÜnür `=` is more error prone in that it only works if the module's import() function does version checking if it sees a version (as Exporter does). The space makes Perl call VERSION in addition to import, which is the most correct thing to do – ysth Aug 04 '17 at 21:05
  • @ysth Thank you for the correction. – Sinan Ünür Aug 04 '17 at 21:34

2 Answers2

3

You may have multiple versions of perl present on your system, each of which will look in different places and have different sets of installed modules.

Use the same perl interpreter as your code does and you should be able to verify that it is there with:

/path-to-that-perl/perl -le'use Spreadsheet::WriteExcel; print $INC{"Spreadsheet/WriteExcel.pm"}'

There should also be a perldoc installed there that will look in the same places:

/path-to-that-perl/perldoc -lm Spreadsheet::WriteExcel

It is also possible, though less likely, that the code in question is adding additional directories to @INC that says where perl will look for modules, via the -I switch, use lib, PERL* environment variables, a sitecustomize script, or directly modifying @INC.

ysth
  • 96,171
  • 6
  • 121
  • 214
  • I was able to find out the location for all the modules installed , the path was mentioned in the PATHLIB variable , when I echoed it I got the location, to execute any perl program I think I need to initialize PATHLIB before executing on my system. – Vicky Aug 22 '17 at 11:45
1

Run perl -e "use Spreadsheet::WriteExcel" if it is installed you do not get an error.

Jens
  • 67,715
  • 15
  • 98
  • 113
  • I get this `Can't locate Spreadsheet/WriteExcel.pm in @INC (@INC contains: /usr/perl5/5.8.4/lib/sun4-solaris-64int /usr/perl5/5.8.4/lib /usr/perl5/site_perl/5.8.4/sun4-solaris-64int /usr/perl5/site_perl/5.8.4 /usr/perl5/site_perl /usr/perl5/vendor_perl/5.8.4/sun4-solaris-64int /usr/perl5/vendor_perl/5.8.4 /usr/perl5/vendor_perl .) at -e line 1. BEGIN failed--compilation aborted at -e line 1.` – Vicky Aug 04 '17 at 15:28
  • Then it is not installed – Jens Aug 04 '17 at 15:56
  • I don't think so as I ran perl -e "use DBI" and i got the same error Can't locate DBI.pm in @INC isn't the DBI comes by default with the perl ? I went to the lib folder of my perl but dont see DBI there .Being new to perl learning I am totally confused – Vicky Aug 20 '17 at 14:38
  • @Vicky No, DBI does not come with the standard perl distribution. – melpomene Aug 20 '17 at 14:58
  • @melpomene : can you help me locate it ? I know it is installed in my system but I just cannot hapen to locate it ? – Vicky Aug 20 '17 at 15:00
  • @Vicky Why do you think it is installed on your system? – melpomene Aug 20 '17 at 15:00
  • @melpomene: because code written by other users using these modules works perfectly – Vicky Aug 20 '17 at 15:01
  • @Vicky How are you running that other code? – melpomene Aug 20 '17 at 15:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/152387/discussion-between-vicky-and-melpomene). – Vicky Aug 20 '17 at 15:03