Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I created a module in placed in a directory called Ops that is in the same folder as a script from which I'm calling it. Whenever I execute the script from within the folder that it is located in, all works fine. In other words I type ./scriptname.cgi at the command line.

However, if for example, I'm in the /root directory and I call /usr/local/cgi-bin/scriptname.cgi it complains that it can't find the module Ops::Module.pm. Why is that? I have the folder "Ops" located in the same directory as scriptname.cgi. Why would work when I'm calling it from that directory,but not from a remote directory?
Thoughts? Thanks.

Replies are listed 'Best First'.
Re: Module Location
by dragonchild (Archbishop) on Nov 07, 2001 at 01:20 UTC
    When you do a use, @INC is checked from the directory you execute the script in, not the directory the script is located. Hence, I would do an full directory in your use lib, in the form:
    use lib '/my/directory/with/Ops/in/it'; use Ops;
    That way, you'll be able to call your script from anywhere.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: Module Location
by CubicSpline (Friar) on Nov 07, 2001 at 01:31 UTC
    I'll be the first to admit that I don't know a lot about modules, especially writing your own. But it sounds to me like maybe you have a problem with the current working directory when you run your script. I'm wondering if, since you call the script from /root, it doesn't look for the Ops directory in /root (/root/Ops). Just out of curiosity, if you create the /root/Ops folder and stick that module in it, does it work?