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

quick question: I have a module installed that is working fine. I'm writing a test script that will require me to modify this module. Can I just put the module in a folder where the script is and have the script use that version of the module instead of the one installed?
For instance, module Temp::Temp. If inside the folder where my script is, I create a folder called Temp and put the module in there. Will my script use the version of Temp installed on the system or the one located in the folder?

Replies are listed 'Best First'.
Re: New module usage
by Adam (Vicar) on Feb 23, 2001 at 01:10 UTC
    The search path for modules is compiled into perl, but you can adjust it locally in your script using the lib pragma:
    use lib '.';
    That will make all the following use statements check the current directory first. Not a good idea in live software, but very handy when testing stuff.
Re: New module usage
by TheoPetersen (Priest) on Feb 23, 2001 at 01:33 UTC
    While I don't disagree with use lib or adding -I to the shebang line, you might consider using the PERL5LIB environment variable instead, especially if the situation is temporary and you are going to install your changes system-wide eventually.

    By using the environment variable you don't have to remember to pull the switch or use statement out of your code. I've preferred it that way since I had a puzzling error caused by an old copy of a module I left in a directory long after I was finished with it.

    See also perlman:perlrun

      Also, adding the _full_directory_path_ to PERL5LIB means that your program will work even if you don't cd into its directory to run it.

      In short, put your test module _some_place (site_perl?), then make sure that's first in PERL5LIB for your login. Even if you eventually install it system wide, just remove the copy from your test directory, and you don't have to remember to change your PERL5LIB back.

      p
        If you're going to be doing this sort of thing a lot, then you might want to add '.' to the front of PER5LIB. Then you'll always look in the local directory first.
(Guildenstern) Re: New module usage
by Guildenstern (Deacon) on Feb 23, 2001 at 01:13 UTC
    It will use the one installed on the system before the one you have modified. I ran into the same problem while making a bug fix in a module I've written. I got my script to see the correct module by using the command line switch -I. (that's a dot). That will make the current directory the first entry in @INC, which means it will be searched first for modules. That should cause your module to be located before the installed one and used instead.

    Guildenstern
    Negaterd character class uber alles!
      Where do I enter in the command line switch? Can I just add it to my script somehow?
        Yes. My answer is equivalent to -I, but is internal to the script. Also, you can put flags on the #! line at the begining of your script:
        #!/usr/bin/perl -w -I. use strict; use ModuleToTest;
        is the same as
        #!/usr/bin/perl -w use strict; use lib '.'; use ModuleToTest;
        I happen to like the use_lib method better, as it is more readilly apparent what you are doing (but still might warrant a comment.)
        To do it that way you type it in the prompt like this:
        C:\>perl script.pl -l.

        - p u n k k i d
        "Reality is merely an illusion, albeit a very persistent one." -Albert Einstein

        Well, you can do like Adam suggested. I believe (but am not 100% sure) that you can make the -I. part of your hash-bang line: !#/usr/bin/perl -w -I.
        I'm coming from the NT world, so I'm used to using it as I call the script: perl -I. myscript.pl

        Guildenstern
        Negaterd character class uber alles!
Re: New module usage
by petral (Curate) on Feb 24, 2001 at 08:09 UTC
    Another keep-it-simple method which doesn't require you to be in the same directory as your script and (development) module:
    use FindBin qw($Bin); use lib $Bin;

    p