Perl – @INC

@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:

Tags:


Share This


 


2 Responses to Perl – @INC

  1. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>