in reply to Referring to a module above the CWD

Your question is slightly confusing, and as such, the answers so far are also broken.

Do you want:

  1. A module in the directory above where the script is located? or
  2. A module in the directory above the current working directory?
These are two very different questions, and require different answers. Hint: adding ".." to the @INC path (whatever way you do that) accomplishes #2 but not #1. And you mention CWD, which also hints at #2. But I really think you might want the answer to #1 instead, as that's usually the one that most people really end up needing.

As a way of understanding the difference, suppose I issued the following:

cd /usr/tmp /long/path/to/your/script with some args
Would you want to look in "/long/path/to/your" (#1) or "/usr" (#2)?

Replies are listed 'Best First'.
Re^2: Referring to a module above the CWD
by Spidy (Chaplain) on Jun 17, 2007 at 00:21 UTC
    Hi merlyn,

    For the moment, I'm only looking for the answer to the second question.

Re^2: Referring to a module above the CWD
by jsegal (Friar) on Jun 17, 2007 at 12:49 UTC
    Later in this thread, Spidy, you say you want #2, but if someone else reading this wants the answer to #1, the "FindBin" module comes in handy.

    E.g. suppose you have a top directory, and underneath it you have bin and lib, and under lib you have your modules. You could use:
    use FindBin qw($RealBin); use lib ("$RealBin/../lib");
    To access your modules.

    In this case, $RealBin will be set to the directory of your script, and if you have a set way to navigate to your libraries from that directory, you can make use of that.

    This technique can be useful, for example, if you have multiple versions of an application + set of libraries around, and want them both to be installed at the same time without version conflicts.


    --JAS