I wrote some modules, and trying to run them. How I tell where to take the module from?
I am writing in Windows, and tried to put it in c:\perl\lib
but it didn't help.
Can I put it in the same directory, as the file that calls the module?
Perl uses the paths in:
@INC
to search for modules. (.pm files)
If you:
perl -e 'print join "\n", @INC;'
you'll see what paths are currently being searched for modules. (This @INC list is compiled into the perl executable)
Then you can:
BEGIN { unshift @INC, 'C:\mylibs' }
or
use lib 'C:\mylibs'
and place MyModule.pm inside C:\mylibs to enable:
use MyModule;
This is exactly what local::lib is designed to handle. By default, use local::lib;
will prepend ~/perl5
to your module search path (@INC
), but you can easily tell it to add another directory.
If you're doing it with a fixed directory (rather than one relative to your home directory), then you're probably just as well off with use lib 'PATH'
.
If this is for code that will only be run from the command line, another option would be to create a PERL5LIB
environment variable which points to your personal module directory. This would affect all Perl run by your user account from the command line, so you wouldn't need to modify your Perl code at all with this method, but it's trickier to set up for non-command-line code (e.g., web scripts) and, if the code will be run by multiple users, PERL5LIB
will need to be set for all of them.
I wouldn't recommend mucking about with @INC
directly in any case. There are plenty of easier ways to do it these days.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With