lib

Permits adding additional directories to Perl’s default search path at compile time. The directories are added at the front of the search path.

use lib list;

adds the directories specified in list to @INC.

For each directory $dir in list, lib looks for an architecture-specific subdirectory that has an auto subdirectory under it—that is, it looks for $dir/$archname/auto. If it finds that directory, then $dir/$archname is also added to the front of @INC, preceding $dir.

Normally, you should only add directories to @INC. However, you can also delete directories. The statement:

no lib list

deletes the first instance of each named directory from @INC. To delete all instances of all the specified names from @INC, specify :ALL as the first parameter of list.

As with adding directories, lib checks for a directory called $dir/$archname/auto and deletes the $dir/$archname directory from @INC. You can restore @INC to its original value with:

@INC = @lib::ORIG_INC;

Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.