Re: 'use' doesn't work for files in local directories

Gisle Aas (aas@bergen.sn.no)
Fri, 09 Feb 1996 10:02:16 +0100


> However, when I try to use 'use', perl tells me it can't find the requested
> module.  Perl CAN find modules in the regular perl directory.  

Your problem is that 'use LWP' statement runs before you set the library path in @INC.  All 'use' happen at compile time. Instead of unshift(@INC,$something) you should write:

   use lib "lib";

Alternatively you might put your whole @INC init block inside BEGIN { } like this:


> I get this error message: 
> Can't locate LWP.pm in @INC at test.pl line 17.
> BEGIN failed--compilation aborted at test.pl line 17.
> 
> Here is the code that fails:
> =============snip
> #!/usr/local/perl -w
> 

BEGIN {

> $scriptsDir="/public_WWW/utilities";
> $wwwLibDir="lib"; 
> unshift(@INC,$wwwLibDir);
> unshift(@INC,$scriptsDir);
> 
> #check that what we think is in @INC is.
> foreach $item (@INC) {
>     print "|$item|\n";
> }

}

> 
> require "tmp-pub-lib.pl";       # finds this (in $scriptsDir) just fine
> 
> use Cwd;                        # this works
> use LWP;                        # this DOESN'T work
> ==============snip

-- 
Gisle Aas                                         <aas@a.sn.no>
Schibsted Nett AS                                 http://www.sn.no/~aas/