0
votes

I need to use MyModule.pm in perl script and add it to @INC

1. use lib "./MyModule";
2. use MyModule::Config;

MyModule located in the same folder whith script, but when I start my script I have

Can't locate MyModule/Config.pm in @INC (you may need to install the MyModule::Config module) (@INC contains: ./lib ./MyModule /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5) at script.pl line 2. BEGIN failed--compilation aborted at script.pl line 2.

Glad to any help

2
For your error, see this Perl Maven link. - vkk05
What is the path to your module from the current directory? - brian d foy

2 Answers

2
votes

There are a couple of possibilities here. It depends on how your module is written.

If your module code starts with:

package Config;

Then you need:

use lib './MyModule';
use Config;

If your module starts with:

package MyModule::Config;

Then you need:

use lib '.';
use MyModule::Config;

(The second option is probably the best.)

2
votes

See the use lib documentation at https://perldoc.pl/lib.

Your code as written is trying to load ./MyModule/MyModule/Config.pm.

Also see
https://perldoc.pl/perlmodstyle
https://perldoc.pl/functions/require

HTH