4

I have a script that uses modules that are external to the standard Perl library and would like for some way to use them. I don't have permissions to install them into the Perl lib directory and was wondering if I could just have these external modules reside in my scripts directory.

I have read about using FindBin but it seems to not work. Am I using it correctly?

Right now I want to use 3 modules I want to use (2 being directories). So lets say my script is in Dir1, then my modules will be in a subdirectory of Dir1 called Dir2.

So assuming 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 seems to run but it doesn't do anything. So I am pretty sure it is not importing the modules correctly.

Thanks

urbanspr1nter
  • 1,347
  • 2
  • 16
  • 25
  • Consider [local::lib](http://p3rl.org/local::lib) instead. From the [Stack Overflow Perl FAQ](http://stackoverflow.com/questions/tagged/perl?sort=faq): [How can I use CPAN as a non-root user?](http://stackoverflow.com/questions/2980297/how-can-i-use-cpan-as-a-non-root-user) – daxim Dec 11 '11 at 19:19

1 Answers1

7

The proper way to do it would more likely be either:

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

or:

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

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

Check out FindBin and lib's documentation.

JB.
  • 40,344
  • 12
  • 79
  • 106