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

J

Jennifer

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?
 
T

Tad McClellan

Jennifer said:
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';
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top