user1194032 user1194032 - 1 year ago 69
Perl Question

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?

Answer Source

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/...';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download