Perl uses by default the array @INC as include path when searching for modules to load. This path is compiled into the perl binary when building it from source and can be printed by running perl -V, which will show something like:

$ perl -V
Compiled at Jun 22 2012 13:27:28

1. Using the module lib

The standard module lib can be used to specify an explicit path to include. It must be stated at the top of the script:

use lib "/opt/special/plib";
use strict;
use warnings;

2. Using the switch ­I at the command line

The switch ­I can be used to specify additional library locations when invoking the interpreter.

perl -I /opt/special/plib

3. Using the switch ­I in the first line of the script

The same ­I switch can be added to the interpreter specification.

#!/usr/bin/perl -I /opt/special/plib
use strict;
use warnings;

4. Manipulating @INC directly

The array @INC can be manipulated directly using array operations

unshift(@INC, "/opt/special/plib");
use strict;
use warnings;

This is the same as using the module lib, which in fact does something like this.

5. Using the environment variable PERL5LIB

The environment variable PERL5LIB can be used to specify additional include directories when running a perl script.

> export PERL5LIB=/opt/special/plib  #Adding this sequnce to 
/etc/profile, then the @INC would be changed persistently.
> /path/to/

6. Changing @INC at compile time


电子邮件地址不会被公开。 必填项已用*标注