Ano-Tech Computers
Enter keyword:

Perl: How to use modules in a custom directory
Problem:
When trying to "use" modules in a custom directory, perl says it can't find the module in any of the directories in @INC. If I try to manually add the directory to @INC, perl seems to ignore it.
 
Solution:
Modules are actually "used" by perl when the script is parsed, now while it is running. This means that any changes to @INC at runtime will happen only AFTER perl searches for the modules to use.

Instead, a "lib" pragma exists for this purpose. To use Custom.pm:
use lib "/my/module/directory"
use Custom;

 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles