Forum Moderators: coopster & phranque

Message Too Old, No Replies

How to get Perl to use included libraries before shared ones

old version of SOAP::Lite getting loaded instead of current one

         

insight

4:34 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



In a scripting I'm brewing up I use the following lines to load SOAP::Lite for use by my script:

use lib qw(~/www/cgi-bin);
use SOAP::Lite;

It works great for my shared hosting account that have no SOAP::Lite installed. On hosts with an older installed SOAP::Lite module (Buggy .51 release) the script used that module instead of the one I include using the lines above.

How do I get Perl to use the module I include instead of the system one?

jollymcfats

4:53 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



You can manipulate the include path directly to put your directory first:
unshift @INC, "~/www/cgi-bin";

jollymcfats

5:00 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



Actually, re-reading the perldoc for 'use lib' (its been a while),
BEGIN { unshift @INC, ... }
is what
use lib
does already.

So it should already be working for you. You might dump out the contents of @INC before your

use Soap::Lite
to see what the include path really is.

Something like this will dump the @INC path to the error log or stderr:


use lib qw(~/www/cgi-bin);
BEGIN { use Data::Dumper; print STDERR Dumper(\@INC); }
use SOAP::Lite;

insight

5:26 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



Thanks for the replies. It turns out it was prepending "~/www/cgi-bin" (probably doesn't understand the "~" home dir notation) to the @INC array just fine, but didn't know how to make sense of it. It worked on the site without any system-wide SOAP::Lite installation because the last element of the @INC array was ".".

I changed the use lines to be:

use lib qw(.);
use SOAP::Lite;

so that it could find the SOAP files in /cgi-bin/SOAP from where the script executes /cgi-bin.

It's certainly not the "right way to do things"(TM), but it is very portable for use on many sites and file structures.

jollymcfats

5:34 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



If you liked the home-dir relative path, you could expand the tilde's at use-time:

use lib glob('~/www/cgi-bin');