Reputation: 185
Let me describe my question.
I have created a new perl module ex:
Module : sample/lib/module/sample.pm
setenv SAMPLE /local/username/sample
I am using this module in multiple files and am using
use lib "$ENV{'SAMPLE'}/lib";
in each and every file i am using the module.
Is there a better solution ? instead of adding in each and every file the lib location to search for.
I tried adding it in the main script which calls other scripts but it doesn't work. I get the error lib not found @INC.
Upvotes: 0
Views: 444
Reputation: 69314
There are basically three ways to manipulate Perl's @INC
variable (which is what you're trying to do here).
use lib
within your program. This is probably the best approach, but it can lead to having to edit a lot of files (as you've worked out).-I
command line option (either when you're calling Perl or on your shebang line). I've rarely seen this approach used.PERL5LIB
environment variable to a colon-separated list of directories. This means that you avoid having to hard-code the directory into every file, but you need to be sure that the environment is set up correctly before you execute your program.I think that in your situation, I'd be looking at option 3.
Upvotes: 1