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

G'day guys
I was just wondering if it is possible to place a perl module within the directory where a perl program that uses the module is placed.
If so how do i redirect the perl program to look within the directory of the perl program instead of looking in the perl lib directory files.

Thanks for the help mate
Chad
  • Comment on Perl modules possible to place some where else

Replies are listed 'Best First'.
Re: Perl modules possible to place some where else
by eserte (Deacon) on May 10, 2004 at 14:26 UTC
    This is usually done with the FindBin and lib modules:
    use FindBin; use lib "$FindBin::Bin";
Re: Perl modules possible to place some where else
by matija (Priest) on May 10, 2004 at 14:27 UTC
    Not "instead of" but "before":
    use lib "/root/of/your/module/hierarchy";
    That will make perl look into that directory tree first - only if the module isn't found there, will it start looking through the other lib directories.

    Replace the string in quotes with the true root of your hierarchy, naturally...

Re: Perl modules possible to place some where else
by rinceWind (Monsignor) on May 10, 2004 at 14:30 UTC
    Alternatively, pass the environment variable PERL5LIB to be a PATH of one or more lib top level directories.

    This avoids having to change any scripts.

    --
    I'm Not Just Another Perl Hacker

Re: Perl modules possible to place some where else
by vek (Prior) on May 10, 2004 at 20:27 UTC

    As others have pointed out, a use lib '/path-to/your-module/'; is what you need in your program.

    If you want to install a module from the CPAN in a non-standard lib directory, just use the following:

    perl Makefile.PL LIB=/your/lib/path PREFIX=/your/lib/path
    -- vek --
Re: Perl modules possible to place some where else
by revdiablo (Prior) on May 10, 2004 at 16:35 UTC

    For other monks' further reference, since this question is so frequently asked, they have handily placed it in the FAQ. There are even two entries discussing it. These can be viewed by running perldoc -q "my own" and perldoc -q runtime at a command prompt, or are available online here and here.

    Update: I just noticed perldoc -q lives, available here, which gives the same solution that eserte posted earlier.

Re: Perl modules possible to place some where else
by Tomte (Priest) on May 10, 2004 at 14:31 UTC

    Edit: forget the code, but read the perldoc!

    use lib '.';

    read more at > perldoc lib your local prompt :)

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

      No.

      First, @INC already includes dot (unless you're root), so this doesn't change a thing.

      Second, the "." here refers to the current directory of the process running the script, not the immediate directory in which the script is located.

      See the other correct answers elsewhere in this thread.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.