Idr
Idr

Reputation: 6250

Use current working directory version of perl module

I am trying to run a perl script and to make it use a module file in the current working directory. I do this because I eventually will need to use the script and module on another machine where I have no control of what or where modules are installed. My problem is that I can get this to work on some machines, but not others.

The script is:

ubuntu@machine-5:/tmp/pig-local$ cat test.pl
#!/usr/bin/perl -w -I ./Text
use Text::CSV_XS ;
print "Hello World\n"

and when executed I get the error:

ubuntu@machine-5:/tmp/pig-local$ ./test.pl 
Can't locate loadable object for module Text::CSV_XS in @INC (@INC contains: ./Text  ./Text /home/ubuntu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi /home/ubuntu/perl5/lib/perl5/x86_64-linux-g
nu-thread-multi /home/ubuntu/perl5/lib/perl5 /etc/perl /usr/local/lib/perl/5.14.2 /usr/local/share/perl/5.14.2 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.14 /usr/share/perl/5.14 /usr/local/
lib/site_perl .) at ./test.pl line 2
Compilation failed in require at ./test.pl line 2.
BEGIN failed--compilation aborted at ./test.pl line 2.

The current working directory does have the Text directory and the CSV_XS.pm module contained in it. I have checked the md5sum on the file and it is the same as the machine where the script works.

ubuntu@machine-5:/tmp/pig-local$ ls Text/
CSV_XS.pm

My OS is:

ubuntu@machine-5:/tmp/pig-local$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 12.04.1 LTS
Release:        12.04
Codename:       precise

and these are the different perl env variables set on the machine:

ubuntu@machine-5:/tmp/pig-local$ env | grep -i perl
PERL5LIB=/home/ubuntu/perl5/lib/perl5/x86_64-linux-gnu-thread-multi:/home/ubuntu/perl5/lib/perl5
PERL_MB_OPT=--install_base /home/ubuntu/perl5
PATH=/home/ubuntu/perl5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
PERL_LOCAL_LIB_ROOT=/home/ubuntu/perl5
PERL_MM_OPT=INSTALL_BASE=/home/ubuntu/perl

When I check to see if perldoc knows about the module in question,

ubuntu@machine-5:/tmp/pig-local$ perldoc -l Text::CSV_XS
./Text/CSV_XS.pm

It thinks the module exists in the current working directory.

Any ideas about how to get this to work?

Thanks

Upvotes: 0

Views: 905

Answers (2)

ikegami
ikegami

Reputation: 385764

You did not properly install the module. It consists of more than a .pm file. It's not the .pm it can't find, it's the .dll/.so that goes with it.

Upvotes: 5

wholerabbit
wholerabbit

Reputation: 11546

Look:

@INC contains: ./Text 

Guess what is not in that directory? Another directory named "Text". Hence, perl doesn't find Text::CSV_XS there (it would find just plain CVS_XS tho).

Try -I . or:

BEGIN { unshift @INC, '.' }

Upvotes: 0

Related Questions