pupil
pupil

Reputation: 185

including perl module in a different directory in a single location which can be used for multiple files

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

Answers (1)

Dave Cross
Dave Cross

Reputation: 69314

There are basically three ways to manipulate Perl's @INC variable (which is what you're trying to do here).

  1. You can use 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).
  2. You can use the -I command line option (either when you're calling Perl or on your shebang line). I've rarely seen this approach used.
  3. You can set the 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

Related Questions