FindBin for perl modules that are in my script directory

I have a script that uses modules that are external to the standard Perl library and would like to use them somehow. I do not have permission to install them in the Perl lib directory, and I was wondering if I could just use these external modules in my script directory.

I read about using FindBin, but it doesn't seem to work. Am I using it correctly?

Now I want to use 3 modules that I want to use (2 are directories). So let's say my script is in Dir1, then my modules will be in a subdirectory of Dir1 called Dir2.

So, if FindBin finds Dir1, then all I have to do is this?

use FindBin '$Bin'; use Dir2 "$Bin/Dir2"; use Dir2::SubDir_ofDir2_1::Module1; use Dir2::Module2; use Dir2::Module3; 

My program works, but does nothing. Therefore, I am sure that it does not import modules correctly.

thanks

+4
source share
1 answer

The correct way to do this is most likely to be:

 use lib "$FindBin::Bin/Dir2"; use SubDir::Module1; 

or

 use lib $FindBin::Bin; use Dir2::Subdir::Module; 

Both will find the files, the behavior will depend on whether the modules declare themselves inside package Dir2 or not.

Check out FindBin and lib documentation.

+7
source

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


All Articles