I use use lib "./DIR"
to grab a library from a folder elsewhere. However, it doesn't seem to work on my server, but it works fine on my local desktop.
Any particular reasons?
And one more question, does use lib
get propagated within several modules?
Two situations:
Say I make a base class that requires a few libraries, but I know that it needs to be extended and the extended class will need to use another library. Can I put the use lib
command in the base class? or will I need to put it in every extending class?
Finally, can I just have a use package
where package contains a bunch of use lib, will it propagate the use lib statements over to my current module? <-- I don't think so, but asking anyways
The .
in your use lib
statement means "current working directory" and will only work when your script is run from the right directory. The server's idea of cwd is probably something different (or undefined). Assuming that the library directory is co-located with with script and private to it you want to do something like this instead:
use FindBin;
use lib "$FindBin::Bin/DIR";
A use lib
statement affects @INC
-- the list of locations perl searches when you use
or require
a module. It globally affects the current instance of the interpreter. You should really only put use lib
statements in scripts, not in modules.
In principle, you could have a package MyLibs
that consisted of a bunch of use lib
statements and then use MyLibs
before using any of the packages in those locations, but I wouldn't recommend it.
There's no way to know why it isn't working on your server without more information. In particular, check your server's error logs, and dump @INC
somewhere if necessary, and compare that to your actual library paths.
use lib
modifies @INC
, which is global, so as long as you execute your use lib
before other packages try to include stuff, it will work and all other packages will see the new include paths.
For more on @INC
, see its entry in perlvar.
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