1. Perl
  2. Module
  3. here

lib - Add module search path

The lib module allows you to add a search path for a module.

# Add module search path
use lib 'home/user/local/lib';

In Perl, list of module search paths is stored in the predefined variable "@INC", but the lib module is at the beginning of @INC at compile time. Add the search path to.

# lib module adds path to the beginning of @INC
BEGIN {
  unshift @INC, '/ home/user/local/lib';
}

The lib module is often used in combination with FindBin module. This is an example to add a directory called lib in the directory where the script exists to the module search path.

# Add the lib directory of the directory where the script exists to the search path
use FindBin;
use lib "$FindBin::Bin/lib";

FAQ about lib module

Q. Is there a way to add a module search path other than the lib module?

A. Yes. You can either set PERL5LIB environment variable or specify the -I option when starting the script. The lib module is the most flexible, but it's tightly coupled with scripts and less portable. Think about which method is best for your situation.

Related Informatrion