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

Hi All, I am quite a regular user of PERL and I found a strange problem with a module loading.
Basically, we have a module x.pm which is installed in the lib path of a particular perl installation.That is I am using perl-5.8.1 and it is installed as /proj/myself/bin/perl , then the module x.pm is installed in /proj/myself/lib/perl5/site_perl/5.8.1/x.pm (since I am using perl 5.8.1 ).
Now I have a script y.pl which uses x.pm module ie. y.pl would look something like this:

/proj/myself/bin/perl -w
use x;


Now while invocating this script,I want this module (x.pm i.e.) to be picked up from a different location,say /u/myself/somescrap/ directory.

So I would do something like this:

/proj/myself/bin/perl -I/u/myself/somescrap y.pl

and since -I unshifts @INC with the path specified,the module should be picked up from /u/myself/somescrap location right? (as long as it exist,right?)
But,alas,it is being picked up from the standard installed location /proj/myself/lib/perl5/site_perl/5.8.1/x.pm.
What I'd love to mention is that x.pm internally uses some more modules (say z.pm,a.pm,b.pm etc.) and some of these modules uses "Config" module.
My first impression is that Config module is doing some funda based on the path of the perl executable that we are using and is "forcing" x.pm to be picked up from its installed location.
Can someone help me out?
~Karthik

Replies are listed 'Best First'.
Re: problem with module loading
by coreolyn (Parson) on Jul 29, 2004 at 16:43 UTC

    Much ugliness! Really could have used better description of the problem, especially where it concerns the other module dependencies. The best I can do is through some psuedo code at you to hopefully get you thinking in a good direction

    Basically you need a BEGIN loop to handle your dependencies. The following is real bulky and I have no doubts there are more efficient ways to do this, but I'm just trying to show 'a way' to get you started and it's strictly the first way to come to my head.

    /usr/local/bin/perl -w use strict; BEGIN { # I'd put all the locations I want added into an array my @inINC = "/pathsToTheModulesIWant"; # I'd load all the current values into a different array my @initINC = "/defaultINCPaths"; # Then I'd have an array with all the values I want # pulled from @INC my @badINC = "/modules I don't want"; # (With the problems with interdependencies you may need # to move some modules to there own directory ) # I'd then loop through the initial array and load the # paths I want to keep my $initPath, $badINCPath; for $initPath (@initINC) { for $badINC (@badINC) { unless ( $badINC eq $initPath ); { push (@inINC, $initPath); } } } # Now that you have the order and values of the # paths you want, set @INC @INC = @inINC; } # and On with the programs regularly scheduled execution use x; use y;

    Hope this or the criticism arising from this helps!

Re: problem with module loading
by diotalevi (Canon) on Jul 29, 2004 at 16:35 UTC

    See lib and be sure you are writing your paths correctly. Do also verify that @INC is exactly as you expected it to be.

Re: problem with module loading
by ysth (Canon) on Jul 29, 2004 at 16:38 UTC
    Works for me (assuming you meant a #! at the start of y.pl); try adding this to the top of y.pl:
    print "private x ", (-f "/u/myself/somescrap/x.pm" ? "exists" : "doesn +'t exist"), "\n"; print "dir: $_\n" for @INC; print "$_ found at $INC{$_}\n" for keys %INC;
    and see if it shows anything useful.

    There's no way Config being used by a module that x uses could influence where x is found; x is already loaded at that point.