Perl newbie here with very little time and support to learn Perl but all the expectations from management to use it like a Perl Pro :)
I am using Perl (v5.30.2 by Larry Wall) under Cygwin (windows 10)
My developer issued a new script, that now uses a Perl module I didn't have.
They then sent me the .pm file (which they authored themselves and it is not on any online Perl repo).
I was unable to use CPAN to install that file into my Perl execution environment.
- Where should the .pm file be saved at? (please specify the exact folder)
- How to tell CPAN to install this file for usage? Ideally, a one-time affair, as I don't want to forget installing this file, if I have to do that every time I need to run the Perl script...
- Just in case there may be any security concern from the dear answer-ers: There isn't any security concern here, this is all under an environment that has no connection to the internet.
A Perl module is just a file (or collection of files). You don't have to put them anywhere special, but you need to tell Perl where to find them.
When you call
use
orrequire
with a bareword, Perl translates that module name, likeSome::Module
, into Some/Module.pm (or whatever is appropriate for your system. Anyone still using VMS?).Once it has the filename form of the module, it looks for that subpath in the directories in
@INC
. It tries the first directory. If it doesn't find it it moves on to the next, and so on down the line. These directories are decided when someone configures and installs Perl. And, before v5.26, it included the current working directory (see v5.26 removes dot from @INC and Doesn't Perl include current directory in @INC by default? )But, you can tell Perl where else to look. perlfaq8 has How do I add a directory to my include path (@INC) at runtime?. ikegami also showed
FindBin
in the comments (How do I add the directory my program lives in to the module/library search path?).Beyond that, you can tell require to load a path, although you then need to ensure that the program can find that path even if someone runs it from another directory