Enable perl module from another location

my problem is the following

  • I have lib in location. / abc / def / lib
  • I use it on the go. /abc/xyz/lib/tuv/abc.pm

I run the code from another place generally something like. / abc / xyz / blah 1 / blah2 /../../. I am running the code here.

I created env params

setenv def ./abc/def 
setenv xyz ./abc/xyz

I tried the following solutions

  • Begin { push(@INC, $ENV{def}."/lib" ) }
    Along with providing a path for other libraries that I used, use lib $ ENV {xyz}. "/ lib"

    This solution did not work. I get an error in the library. / abc / def / lib is not included.

  • I tried FindBin

    # for the libs present in ./abc/def/lib
    use FindBin;
    use lib "$FindBin::Bin/../../";
    use mylib::abc;
    use mylib::def;
    

(I tried to give a way also to the roots, where to start searching in FindBin)

I tried to use different combinations, but not sure why it is not working. Can someone point out what I'm doing wrong, or my understanding of FindBin is wrong.

+4
2

FindBin . , $FindBin::Bin , script. , ...

use lib $FindBin::Bin . '/../../etc';

'/../..' script lib.

, , - . Can't locate Your/Module/Name.pm, @INC - . , , lib, .

0

, . , " , " . , "Can not locate [some module] in @INC".

() @INC. .

  • use lib
  • ( shebang) -I
  • PERL5LIB

@INC, .

@INC. , , @INC - use , BEGIN ( use ). , , BEGIN, BEGIN - .

, , , FindBin, , . FindBin , (, ./bin, ./lib).

, @INC (./abc/xyz/lib/tuv/abc.pm). , FindBin $FindBin::Bin . $FindBin::Bin , , .

, ( ), , . , PERL5LIB .

+3

Source: https://habr.com/ru/post/1650519/


All Articles