12.7. Keeping Your Own Module DirectoryProblemYou don't want to install your own personal modules in the standard per-system extension library. Solution
You have several choices: use Perl's
-I
command line switch; set your Discussion
The % perl -e 'for (@INC) { printf "%d %s\n", $i++, $_ }'
The first two directories, elements 0 and 1 of The next pair, elements 2 and 3 above, fulfills roles analogous to elements 0 and 1, but on a site-specific basis. Suppose you have a module that didn't come with Perl, like a module from CPAN or one you wrote yourself. When you or (more likely) your system administrator installs this module, its components go into one of the site-specific directories. You are encouraged to use these for any modules that your entire site should be able to access conveniently.
The last standard component,
So sometimes none of the
The first approach involves using a command-line flag,
-I
dirlist
. The
dirlist
is a colon-separated[
1
] list of one or more directories, which will be prepended to the front of the
This technique should not be included in the
Often, a better solution is to set the # syntax for sh, bash, ksh, or zsh $ export PERL5LIB=$HOME/perllib # syntax for csh or tcsh % setenv PERL5LIB ~/perllib
Probably the most convenient solution from your users' perspective is for you to add a use lib "/projects/spectre/lib"; What happens when you don't know the exact path to the library? Perhaps you've allowed the whole project to be installed in an arbitrary path. You could create an elaborate installation procedure to dynamically update the script, but even if you did, paths would still be frozen at installation time. If someone moved the files later, the libraries wouldn't be found.
The
FindBin module conveniently solves this problem. This module tries to compute the full path to the executing script's enclosing directory, setting an importable package variable called To demonstrate the first case, suppose you have a program called /wherever/spectre/myprog that needs to look in /wherever/spectre for its modules, but you don't want to hardcode that path. use FindBin; use lib $FindBin::Bin; The second case would be used if your program lives in /wherever/spectre/bin/myprog but needs to look at /wherever/spectre/lib for its modules. use FindBin qw($Bin); use lib "$Bin/../lib"; See Also
The documentation for the standard Copyright © 2001 O'Reilly & Associates. All rights reserved. |
|