Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Can't locate @INC & not finding files in local directory

Reply
Thread Tools

Can't locate @INC & not finding files in local directory

 
 
Jennifer
Guest
Posts: n/a
 
      06-24-2003
Hello -

I've got several Perl scripts that use custom perl modules which are
called from routines that are in the same directory as the scripts.
For example dir.pl in folder dir references dir_utilities.pl.

I call them with a require at the top of the routine, e.g. require
'dir_utilities.pl';

This worked fine for a number of years and this morning, all my
scripts are erroring with this type of message: Can't locate
dir_utilities.pl in @INC (@INC contains: sys:\perl\lib .) at dir.pl
line 16.

Our web administrator says they haven't made changes to our Perl
install or the web server itself (we are running Perl 5 on a Novell
web server) and I haven't made any routine changes.

It looks as though when Perl is executing the script it is not reading
the local directory as it used to and therefore is not finding the
files there. The files do exist and are unchanged.

I tried adding this to see if I can get it to have the directory
reference:
BEGIN {
push ( @INC, 'sys:\perl\web\dir' );
}

This does stop the error for the require calls, but when other files
in the directory are referenced in the script (HTML templates used for
output, etc) it gives an error that it cannot find these, so it's like
it can find nothing from the directory where the script is.

Does anyone have any suggestions?
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      06-24-2003
Jennifer <(E-Mail Removed)> wrote:

> I've got several Perl scripts that use custom perl modules which are
> called from routines that are in the same directory as the scripts.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


They way you said that makes me think that you lack an understanding
of the fundamentals involved. Let's see if I can help with that...


1)
Routines cannot be in a directory.

_Files_ can be in a directory.

2)
Where the function is _called_ from does not matter.

You are getting a fatal error before getting to where the
function is invoked.


> For example dir.pl in folder dir references dir_utilities.pl.



You are using a relative path to dir_utilities.pl which assumes
that you know what your current working directory (cwd) is.

Do you *know* what your cwd is?


> This worked fine for a number of years and this morning, all my
> scripts are erroring with this type of message: Can't locate
> dir_utilities.pl in @INC (@INC contains: sys:\perl\lib .) at dir.pl

^
^

You have the cwd in @INC, so perl should be able to find it if
your cwd just happens to be the same directory that the main
program is in.

Since perl can *not* find it, your cwd must be different from the
directory where your main program is (assuming sufficient permissions).


> Our web administrator says they haven't made changes to our Perl
> install or the web server itself



If I don't believe that, then I'm pretty sure I know what your
problem is.

If I do believe that, then I have no idea how you can experience
the symptoms you attempt to describe.



What happened when you ran the program from the command line
rather than in a CGI environment?



> It looks as though when Perl is executing the script it is not reading
> the local directory as it used to and therefore is not finding the
> files there.



But there is another plausible explanation as well...

What if the cwd ("local directory"??) is not what it used to be?


> I tried adding this to see if I can get it to have the directory
> reference:
> BEGIN {
> push ( @INC, 'sys:\perl\web\dir' );
> }
>
> This does stop the error for the require calls, but when other files
> in the directory are referenced in the script (HTML templates used for
> output, etc) it gives an error that it cannot find these, so it's like
> it can find nothing from the directory where the script is.



The directory where the script is does not matter at all!

You are concentrating on the wrong thing.

What matters is your current working directory. Sometimes a web server
is configured to make the cwd the same as the directory where the
script is, but sometimes the cwd is set to something else.


> Does anyone have any suggestions?



Use forward slashes in paths whenever possible
(and it *is* possible in this case).


Either:

_force_ the cwd be what you want it to be rather than assuming that
it will be what you want it to be:

chdir 'sys:/perl/web/dir' or die "could not cd to 'sys:/perl/web/dir' $!";

or

use absolute (not relative) paths so that the contents of
@INC are never even consulted:

require 'sys:/perl/web/dir/dir_utilities.pl';


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding the local directory of a file in the python path are Dogue Python 1 05-18-2011 01:53 AM
Locate user temp directory brittonsm@gmail.com Java 2 12-24-2007 09:03 AM
System.IO.Directory.GetDirectories() and System.IO.Directory.GetFiles() are not returning the specified directory Nathan Sokalski ASP .Net 2 09-06-2007 03:58 PM
HOWTO - do local ppm module install (fix "Could not locate a PPDfile") ROC Perl Misc 0 07-09-2005 05:25 PM
WinAPI to locate a file in directory Lakshmi C Programming 2 09-22-2004 06:51 AM



Advertisments