tags:

views:

170

answers:

2

Hi Guys, I have perl module file and test script pl which I use to run some function, and after browsing through the use lib and this previous question here... I still don't know how to do this.

Basically I have a production directory which contains the module file, and I have a test directory file which contains the same module and the test script file. each time I try to run the script file, it will automatically calls the module in the directory. by printing out the @INC, it seems that the production directory is hosted in there. thus I try to remove it by using

no lib qw(prod_dir);

and while printing out the @INC shows that the directory is no longer there, somehow the script is still calling that other module...

I know this probably sounds really dumb, but hope someone can help me see the light here :) thanks.

+6  A: 

After you have required or used the module, check %INC to see where it came from.

For example:

use Data::Dumper;
print $INC{'Data/Dumper.pm'}."\n";

Note that "::" becomes "/" and you append ".pm". That might give you a clue.

Remember that the current directory (".") is usually an entry in @INC. But the first step is finding out what directory the module was loaded from.

Another thing to remember is that the directories in @INC are searched in order. use lib prepends to that list (making it the first-searched directory), so you may just need to add the appropriate directory.

cjm
+2  A: 

Can you say more about what you are trying to do and how you are trying to do it? Is this stuff in a standard Perl distribution structure? If you aren't using the standard distribution structure, can you show us a directory listing so we know where things are? Can you also include the code you use to try to load the module? Just update your original question when you pull together the details.

Typically, I run tests through the build runner, which automatically sets up the right @INC.

If I want to run one test in my distribution, I use the blib module to find the build library which has the development versions of my modules:

 % perl -Mblib t/test.t

Some people do the same thing with prove.

If you aren't using the basic distribution set-up, consider using it. The tools and best techniques rely on it.

If you just have your module and test file in the same directory, have you tried adding the current directory to @INC with PERL5LIB?

brian d foy
@Brian - Yes, it's mod perl and we have a directory where we usually store the rest of the additional pm files that we're using. I'm thinking there might be some circular dependency or something going on here which is causing this problem :(
melaos