sonia hamilton – life on the digital bikepath – sonia@snowfrog.net

2 June 2009

Perl – @INC

Filed under: Perl — Sonia @ 09:34

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

2 Comments »

  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/’;

    Comment by Dean Hamstead — 2 June 2009 @ 10:03

    • I used unshift so my library has highest precedence; push would give lowest precedence.

      Yes, use lib is better; notes updated.

      Comment by Sonia — 3 June 2009 @ 11:00


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.