Perl – @INC
| 02-Jun-2009 | Posted by Sonia Hamilton under Perl |
@INC – like $PATH for do, require, use
Display existing @INC:
- perl -V | tail
- perl -le ‘print for @INC’
Modify @INC:
- in a script: unshift @INC, “/home/sonia/lib/perl”
- better: use lib ‘/home/sonia/lib/perl/’;
- for shell: export PERL5LIB=/home/sonia/lib/perl
- onetime at command line: perl -I/home/sonia/lib/perl foo
Also:
- perldoc perlrun
- perldoc lib
- Intermediate Perl
Share This
you can push or unshift on to @INC.
just depends if you want it on the end or front. but it doesnt make much difference as perl will search all of them.
a better way is to ‘use lib’ at the top of your program
ie
use lib ‘/home/sonia/lib/perl/’;
I used unshift so my library has highest precedence; push would give lowest precedence.
Yes, use lib is better; notes updated.