in reply to How to Add path to @INC

The easy answer is:

use lib qw(/my/path/to/add/);
This adds directories to @INC at compile-time, so they're valid in subsequent use statements. Try perldoc lib for more information on this.

The longer answer:

You could do this to add things to @INC:

push @INC, '/my/path/to/add';
because, @INC is just a Perl array, nothing special. However, use statements are executed at compile time, not at runtime, so if you simply push onto the array, @INC won't be changed until runtime, and your use still won't find what it's looking for.

Pushing things directly onto @INC would work if you're just doing require, which happens at runtime. But the short answer is best: just  use lib and you'll be happy.

Alan

Replies are listed 'Best First'.
RE: RE: How to Add path to @INC
by Fastolfe (Vicar) on Jul 28, 2000 at 22:30 UTC
    The only way to get @INC changes to be noticed at "compile" time would be to put them in a BEGIN block. But yah, 'use lib' is much preferred.