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

Discussion in 'Perl Misc' started by Jennifer, Jun 24, 2003.

  1. Jennifer

    Jennifer Guest

    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?
    Jennifer, Jun 24, 2003
    #1
    1. Advertising

  2. Jennifer <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jun 24, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Evanchik

    Can't locate POE.pm in @INC

    Michael Evanchik, Sep 22, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    542
    Sam Holden
    Sep 24, 2003
  2. Gary Hartl

    Perl can't locate a .pm in @INC

    Gary Hartl, Nov 4, 2003, in forum: Perl Misc
    Replies:
    7
    Views:
    162
    Gary Hartl
    Nov 5, 2003
  3. Newbie
    Replies:
    3
    Views:
    1,349
    Sisyphus
    Feb 6, 2004
  4. Justin Wyllie
    Replies:
    5
    Views:
    234
    Peter Pan
    Jan 11, 2005
  5. Replies:
    3
    Views:
    1,587
Loading...

Share This Page