views:

77

answers:

3

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?

+1  A: 

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.

Chas. Owens
Unfortunatelly, it's not my script, so I cannot modify it. I just can run it with options
Nikita
+5  A: 

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?)

DVK
I've tried every aproach from the list/ but it doesn't help/ I still cannot use my own module(
Nikita
You need to specify the exact package name for us to help in more detail - provide the `use xxx` line
DVK
Also, please specify the exact directory structure of the module code
DVK
+1  A: 

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 ...
brian d foy
justintime
The benefits and risks depends what you are doing. One adds only what you say and one adds arch and version dirs to @INC. Whether that's good or bad depends on what you want.
brian d foy