[pm-h] How to update @INC from within a script?

G. Wade Johnson gwadej at anomaly.org
Tue Dec 6 17:21:14 PST 2005


On Tue, 06 Dec 2005 18:23:21 -0600
Jay Vogt <jvogt at houston.oilfield.slb.com> wrote:

[snip]

> Wade - the reason for the perl with non-existent directories for @INC
> is because it is sent to clients who can install in any directory they
> want. I don't suppose that @INC can point to directories with
> relative paths or variables in them.

If the libraries you are trying to access are part of your program, a standard
approach combines "use lib" with the FindBin module.

1. Put your libraries in a lib subdirectory of the directory where your script
will live (as part of the install).

2. At the top of your script add the following:

use FindBin;
use lib "$FindBin::Bin/lib";

Now any modules you include will also reference the lib subdirectory of your
installation.

The $FindBin::Bin variable contains the directory your script executed from.
The path in the 'use lib' can be any path relative to that. (including using
.. to go to parent directory, etc.)

I've found this useful in a few installations.

I believe FindBin is available back through Perl 5.6.

G. Wade

-- 
Beware of bugs in the above code; I have only proved it correct, not tried
it.                                                  -- Donald Knuth


More information about the Houston mailing list