I have a dir called foo
, and in that I have lib
and bin
. The scripts in bin
need stuff in lib
. I do something like this:
#!perl use strict; use warnings; use lib '../lib'; use Foo; # <-- comes from lib
But that means I have to be in the bin
dir to run the script. Surely there is a better way. What's the Right Way to do this?
It is typically used to add extra directories to Perl's search path so that later do, require, and use statements will find library files that aren't located in Perl's default search path.
if you use “use” your file should be named with a . pm extension and placed in the same folder as the main perl script: use Filename; or you can use the “use lib” pragma to add modules to the @INC array and put them in any folder you want as long as you tell “lib” where you put your modules.
The standard FindBin
module does what you want.
use FindBin; use lib "$FindBin::Bin/../lib";
perldoc FindBin
for more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With