I don't understand what use local::lib does that regular use lib doesn't. Could someone explain it?
- 16,274
- 24
- 118
- 243
3 Answers
local::lib
Defaults to
~/perl5if you don't specify a directory (whileuse lib;is a no-op).Resolves relative paths to absolute paths before adding them to
@INC. (libjust adds the relative path as-is.)Expands
~and~userin the directory name.Appends
/lib/perl5to the directory you specify. (Souse local::lib '/foo';is somewhat equivalent touse lib '/foo/lib/perl5';.)Prepends
DIR/binto your PATH, so you can use scripts installed by local modules.
- 61,471
- 9
- 126
- 175
use lib adds a directory to your module search path (@INC). It has no effect on anything outside of the program or module which contains the use lib directive.
local::lib is intended to be used to enable a private module installation directory and, if you configure your shell environment in the way that it recommends, this private directory will be used for all Perl module installations (whether via CPAN or manual make install) and modules installed there will be made available to all Perl programs/modules run from within your local::lib-aware shell environment.
- 45,363
- 14
- 64
- 102
Regular use lib foo is almost as simple as:
BEGIN { unshift(@INC, foo) }
Whereas use local::lib sets many other Perl environment variables to make sure you can install modules locally, see the source.
- 102,279
- 44
- 260
- 354