开发者

How can I include Perl modules with paths relative to the program?

I have a Perl script which uses开发者_如何学运维 installed packages. One is a Perl package another one is Perl XS package.

Now I want to call this script but use not installed packages, but packages with the same name by path.

I used perl -I /home/.../lib script.pl but it doesn't work

How can I do it?


For various ways of affecting where your modules are loaded, please review this SO posting:

How is Perl's @INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?)


You can use the lib pragma to prepend directories to the path perl uses to find modules.

So, if there is a module named Foo installed in the default directories and a different version installed in /home/cowens/perl5 you can say

use lib "/home/cowens/perl5";
use Foo;

and perl will find the version in /home/cowens/perl5.


Can you show us a recursive listing of the directory where you're storing the modules you want to use? An ls -R could help us figure out if you have the right paths.

When you use the -I switch, you have to ensure you get the right path in there. If you use a module:

 use Some::Module;

Perl actually looks for:

 $lib/Some/Module.pm

The $lib is one of the directories in @INC. Another way to say that though, is that if the particular directory is not in @INC, Perl isn't going to look in it. This means that Perl won't automatically look in subdirectories for you

If your module is not at that location, Perl is not going to rummage around in that $lib to look for it. Your XS module is probably not stored like that. It might have a Perl version and archtype in the path, so you might find it in:

 $lib/5.10.1/darwin-2level/Some/Module.pm

You need to add those paths yourself if you are using -I.

However, you can load modules on the command line. It's much easier to use lib, which adds the extra directories for you:

 perl -Mlib=/path/to/lib ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜