Question

I'm trying to execute a perl script and I've gotten it to work before when I run it in the folder it's located in... ie, the following works.

\higherFolder\folder>UpdateTestCasesScript.pl Test.feature Test_Cases.xls

Buuuuut when I try to run this script on the command line OUTSIDE of that folder

\HigherFolder>folder\UpdateTestCasesScript.pl RealFile.feature folder\Test_Cases.xls

I get this weird error:

Can't locate Spreadsheet/ParseExcel.pm in @INC <@INC contains: Spreadsheet/Parse
Excel.pl C:/Strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry
/perl/lib .> at C:...\HigherFolder\folder\UpdateTestCasesScript.pl line 4

But if you look at the first few lines of my script... they are the following:

#!/usr/bin/perl -w

use lib 'Spreadsheet/ParseExcel.pm';
use Spreadsheet::ParseExcel;

So I have an idea that it may be looking at the wrong @INC somehow, but does anyone have any idea how to fix it??

Thanks!!!

Was it helpful?

Solution 2

. is usually in @INC, making Perl look in the current work directory for modules. It stopped working when you changed the CWD because nothing else in @INC allowed it to find the module.

To look for modules in the relative to the directory in which the script is located:

use FindBin qw( $RealBin );
use lib $RealBin;

By the way, use lib 'Spreadsheet/ParseExcel.pm'; makes no sense whatsoever. The argument should be the directory in which Spreadsheet/ParseExcel.pm is located (more or less).

OTHER TIPS

The argument to use lib should be the folder which contains Spreadsheet/ParseExcel.pm, e.g:

use lib '/higherFolder/folder';
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top