Professional Web Applications Themes

Can't locate INC & not finding files in local directory - PERL Miscellaneous

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 ...

  1. #1

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

    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 Guest

  2. #2

    Default Re: Can't locate INC & not finding files in local directory

    Jennifer <jennlee.2eudoramail.com> 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
    [email]tadmcaugustmail.com[/email] Perl programming
    Fort Worth, Texas
    Tad McClellan Guest

Similar Threads

  1. Finding data files in local directory
    By Xopods in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: April 9th, 05:17 AM
  2. Replies: 0
    Last Post: July 9th, 05:25 PM
  3. Replies: 5
    Last Post: April 14th, 06:36 PM
  4. Finding current directory?
    By Sugapablo in forum ASP
    Replies: 1
    Last Post: October 3rd, 04:07 PM
  5. Locate DLL's in an other Directory than Bin
    By Louis Dascoulias in forum ASP.NET General
    Replies: 0
    Last Post: July 18th, 12:33 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139