user1194032
user1194032

Reputation: 33

Replace @INC in Perl from command line

I have a perl script that used to run in a chroot, and now I'd like it to run outside the chroot. That means that I have to somehow point perl to only look for libraries and modules in /where/chroot/used/to/be/usr/lib instead of /usr/lib. I tried adding the new directories inside the script with push @INC, but then the dependencies are still broken, looking in the old dirs.

Is there any way to tell perl when I run the script that I only want it to look in certain dirs for libraries and modules?

Or is there another better way to make sure dependecies still work when the regular dirs (/usr/bin, /usr/lib etc) are replaced by nonstandard ones?

Upvotes: 2

Views: 1410

Answers (2)

choroba
choroba

Reputation: 241738

To change the @INC from the command line, use the -I option:

perl -lIadded -e 'print for @INC'

In a program, you need to modify @INC early enough, i.e. during compile time. This can be done with

BEGIN { unshift @INC, '/path/...' }

or by using lib

use lib '/path/...';

You can also set the PERL5LIB environment variable:

export PERL5LIB=/path/...
perl -e 'print for @INC'

Upvotes: 3

Arijit Panda
Arijit Panda

Reputation: 1665

you can use lib to put any new directory in your program.

example

use lib "path";

in your case just add this line in the beginning of your program

use lib "/usr/lib/";

hope this will work for you.

Upvotes: 0

Related Questions