Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Mods in different directories

by jmetcalfe (Initiate)
on Jan 30, 2004 at 23:52 UTC ( #325456=perlquestion: print w/replies, xml ) Need Help??

jmetcalfe has asked for the wisdom of the Perl Monks concerning the following question:

Hello All I have a conundrum. I'm building a script that needs to utilize two different perl modules DBI and Date::Calc. The good news is that both of these modules are installed on the unix box. The bad news is they are installed in different directories. One in /usr/local/perl580/bin/perl/ the other in /usr/local/bin/perl. Is there an 'include' tag / switch that I can use,so that I can use both mods? any help is deeply appriciated Feb 5 Thank you all wise perl monks. As it turns out there is a problem with our perl compiler on our box which is rendering the modules unattainable. But I apprciate your responses

Replies are listed 'Best First'.
Re: Mods in different directories
by stajich (Chaplain) on Jan 31, 2004 at 00:31 UTC
    In addition to what the wise monks have already said you can also set the PERL5LIB env variable with one or many directories to search in addition to the ones compiled in your perl exe. You can check and see which dirs perl is searching for modules by doing
    $ perl -V
    See what happens when you set/unset a PERL5LIB variable to the values in the list.
Re: Mods in different directories
by scottj (Monk) on Jan 31, 2004 at 13:32 UTC
    Just because I'm lazy, I'd probably do it this way:
    #!/usr/bin/perl -I/usr/local/perl580/bin/perl/ -I/usr/local/bin/perl # your code here
    I don't recall ever having done this with more than one -I parameter, but I do believe that it should work.
Re: Mods in different directories
by crabbdean (Pilgrim) on Jan 31, 2004 at 00:10 UTC
    "push" the module directory names to the @INC array in the beginning of your script. Alternatively if you want it to search your directories before the ones below use "unshift" instead of "push"

    The @INC Variable

    The @INC array variable contains a list of directories to be searched for files requested by the require function. This list consists of the following items, in order from first to last:

    - The directories specified by the -I option
    - The Perl library directory, which is normally /usr/local/bin/perl
    - The current working directory (represented by the . character)

    Like any array variable, @INC can be added to or modified.

    Dean

    PS. I should add that the @INC array is a system variable.
      Instead of pushing or unshifting modules on @INC yourself, one could do what most people would do, and that's to use the lib pragma.

      use lib is your friend.

      Abigail

        Nice! Funny how I've never noticed that pragma. :-)

        Dean
Re: Mods in different directories
by Sol-Invictus (Scribe) on Jan 31, 2004 at 15:29 UTC
    TIMTOWTDI

    add this to the top of your script:

    use lib('/path/to/module1','/path/to/module2');

    this does the same as

    unshift (@INC,'/path/to/module1','/path/to/module2');
Re: Mods in different directories
by ysth (Canon) on Feb 01, 2004 at 09:15 UTC
    Just a caution...it seems to me very likely that those two directorys were established by different perl installs and that those different perls are very likely to be binary-incompatible.

    Be aware of that and check that any non-pure-perl module you use is built for the actual perl you are running. (Modules that may be a problem should be in an architecture-specific subdirectory that would prevent you from getting the wrong flavor of module, but whoever installed things could have overridden that. Anyway use lib will automatically add those subdirectories if it thinks it can, based on the settings of the Config module it finds.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://325456]
Approved by ybiC
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2022-01-16 10:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (49 votes). Check out past polls.

    Notices?