1

I tried to run a perl script inside my other shell script but I have faced the following snag:

Can't locate new.pm in @INC (@INC contains: /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl

I have specifically set the path where the additional local perl script, i.e, "new.pm" in my Perl script (test.pl) but the error still appears. (perl -V) shows the path of my local Perl. I have further also set the the path of my "new.pm" in my profile file using the command "PERL5LIB".

However, when I run the script on a command line as:

./test.pl 

it does work like a charm.

PS. The she-bang line is properly set. PSS. Platform: linux, OS_vers=2.6.32-5-amd64

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Yacob
  • 515
  • 3
  • 10
  • 18
  • Are you using "use lib $PATH;" ? –  Jan 18 '13 at 15:30
  • How are you invoking `test.pl` in the shell script (`perl ./test.pl` or `./test.pl`)? What does `which perl` give you inside the shell script? – Zaid Jan 18 '13 at 16:41
  • 3
    Your question reads "It doesn't work, but I did everything correctly!" ("I have specifically set the path where the additional local perl script") Perhaps you shouldn't be so sure of that? – ikegami Jan 18 '13 at 18:47
  • Thank you very much for your comments. I invok both as (perl ./test.pl and also test as ./test.pl inside my script (test.pl)). "which perl" does give me the correct path to perl when I run it inside the shell script – Yacob Jan 18 '13 at 23:20

1 Answers1

6

There are multiple ways to do this, but I don't think setting the path is one of them. If "new.pm" is in the /my/lib directory, try any of these:

perl -I/my/lib script-that-calls-new.pl

or

use lib '/my/lib'; ## add this before "use new;"

or

BEGIN { push @INC, '/my/lib'; }; ## same as "use lib" example

or

export PERL5LIB=/my/lib:$PERL5LIB

The path tells your shell where to look for executables. The examples above all tell perl where to find libraries.

martin-g
  • 17,243
  • 2
  • 23
  • 35
gpojd
  • 22,558
  • 8
  • 42
  • 71