What is @INC in Perl?
@INC is a built-in array perl provides. It contains a series of directories, the "search path" for perl when trying to load a module.
When perl encounters a use statement, a require statement, or a do statement:
perl will go over the directories listed in @INC and check if the appropriate file can be found.
In our example, if we try to load Module::Name. Perl will check if there is a Module subdirectory in any of of the directories with a file called Name.pm in the directory.
perl will load the first such file.
Content of @INC
The content of @INC is baked into your version of perl when perl itself was installed and it differs based on the version of perl and your operating system. You can however change it in a number of ways via the PERLLIB and PERL5LIB environment variables, using the -I command line flag, or inside the code by manipulating @INC directly.
Search for @INC and you'll find your
A couple of real examples you can run to see these statements working.
use strict; use warnings; do "File/Basename.pm"; print $File::Basename::VERSION;
use strict; use warnings; print $File::Basename::VERSION; use File::Basename;
use strict; use warnings; require File::Basename; print $File::Basename::VERSION;
Published on 2016-12-22