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

Does anyone know how to use a Perl module without actually installing it in the lib/perl directory? I have the module installed in the same directory as my Perl code. I have tried setting the PERL5LIB environment variable and using findbin, but to know avail. Below is a snippet of setting the environment variable and some of my code.
prompt> setenv PERL5LIB /home/mydir/perlbin #!/usr/local/bin/perl use FindBin; use lib "$FindBin::Bin"; use CPANModule; ...
Result:
Can't locate CPANModule.pm in @INC (@INC contains: /home/mydir/perlbin + /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl .) at myprog.pl line 5.
CPANModule.pm resides in the /home/mydir/perlbin directory, so I don't see where the problem is - and it has permissions to read and execute. Is there a way to use this module locally (without installing it)? Or do I just have to cut and paste the module code into my own code? Thanks.

Replies are listed 'Best First'.
Re: Using Perl Modules
by reptile (Monk) on May 03, 2000 at 15:00 UTC

    I don't know about PERL5LIB, but the use lib pragma should be able to help you. It looks like:

    use lib '/path/to/your/modules';

    That adds the path you enter to @INC for the script you put it in.

    To err is human, to moo bovine.
    
Re: Using Perl Modules
by athomason (Curate) on May 03, 2000 at 12:29 UTC
    I don't know why it can't locate CPANModule, but I can help with using modules locally. Since I don't have root privs on my web server, I have to deal with this problem all the time. Just exploit the fact that '.' is already in your @INC path. Create the appropriate directory structure under the directory of your script and plop the module in.

    For example, the other day I needed to use Convert::UU and don't have the privs to install it, so I created the directory 'Convert' and put UU.pm from the CPAN distribution into it, then just added 'use Convert::UU' as normal.

Re: Using Perl Modules
by btrott (Parson) on May 03, 2000 at 19:00 UTC
    Another option is to use the -I switch:
    #!/usr/bin/perl -w -I/path/to/your/modules
    I always use "use lib", though.

    That's kind of weird that it can't find the module, though, considering that you said it's in the same dir as your Perl script, and "." is in your @INC.