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

I'm having problems trying to use modules downloaded from CPAN, but always the same problem for any module (I've tried Term::ReadKey, Crypt::Passwd, and Digest::MD5). After downloading the modules and putting each in /var/tmp/perl (i.e.- /var/tmp/perl/Digest/MD5.pm, /var/tmp/perl/Crypt/Passwd.pm, /var/tmp/perl/Term/ReadKey.pm) and then adding
use lib '/var/tmp/perl'; use Digest::MD5;
to a script that previously worked, without making any other changes to the script, I now get the following error:
Can't locate loadable object for module Digest::MD5 in @INC (@INC cont +ains: /var/tmp/perl /eng/local/lib/perl5/site_perl/5.6.1/sun4-solaris +/ /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5.6.1 +/usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris /usr/local/lib/perl +5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .) at /var/tmp/jcorr +a/scripts/dev/alumni-shared.pl line 25 Compilation failed in require at /var/tmp/jcorra/scripts/dev/alumni-sh +ared.pl line 25. BEGIN failed--compilation aborted at /var/tmp/jcorra/scripts/dev/alumn +i-shared.pl line 25. Compilation failed in require at ./login.pl line 22.
Then, trying to execute the module directly:
perl /var/tmp/perl/Digest/MD5.pm Can't locate loadable object for module Digest::MD5 in @INC (@INC cont +ains: /usr/local/lib/perl5/5.6.1/sun4-solaris /usr/local/lib/perl5/5. +6.1 /usr/local/lib/perl5/site_perl/5.6.1/sun4-solaris /usr/local/lib/ +perl5/site_perl/5.6.1 /usr/local/lib/perl5/site_perl .) at /usr/local +/lib/perl5/5.6.1/sun4-solaris/DynaLoader.pm line 112 DynaLoader::croak('Can\'t locate loadable object for module Di +gest::MD5 in @INC (@I...') called at /usr/local/lib/perl5/5.6.1/sun4- +solaris/DynaLoader.pm line 180 DynaLoader::bootstrap('Digest::MD5', 2.26) called at /var/tmp/ +perl/Digest/MD5.pm line 16 eval {...} called at /var/tmp/perl/Digest/MD5.pm line 15
I'm a programmer, not a systems administrator, so I don't have much (any) experience installing and configuring Perl, I just want to be able to download and use modules so I don't have to code everything from scratch. Can anyone offer any help on what I'm doing wrong?

Replies are listed 'Best First'.
Re: Problem with DynaLoader and "use"ing downloaded modules
by sauoq (Abbot) on Jul 24, 2003 at 23:53 UTC

    In addition to what others have said, you can install modules in non-standard places by using the PREFIX argument when you run Makefile.PL. For instance, from your examples it appears you might want to install your modules like this:

    $ perl Makefile.PL PREFIX=/var/tmp/perl $ make $ make test $ make install
    You should read perldoc perlmodinstall for a more complete overview of installing modules. You may also find some useful information in tachyon's tutorial, A Guide to Installing Modules, available in the Tutorials section.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Problem with DynaLoader and "use"ing downloaded modules
by Paladin (Vicar) on Jul 24, 2003 at 22:09 UTC
    The easiest way to install modules from CPAN is with the CPAN module that comes with perl.
    perl -MCPAN -e 'install Foo::Bar'
    will install the module Foo::Bar compiling anything that needs to be compiled for XS modules, and putting everything in the right place.

    If you are not the admin for the system, you can install Perl modules in your local home dir as well. There are some directions for doing so in perlfaq8.

      Sadly, due to memory constraints in place on the system (I work for a university), I can't run CPAN myself, so I would have to have my boss run CPAN for any modules I need installed, which is a big hassle for both of us. Which is why I was downloading the modules from CPAN online instead of using the CPAN module to install new modules. Each module I was trying to install is a single .pm file, no package, no Makefiles, etc. just a single .pm file.

        Sadly, due to memory constraints in place on the system (I work for a university), I can't run CPAN myself

        I'm sorry, what? Does the CPAN shell really take up that much more memory than any other Perl script on your system? (It doesn't appear to on mine.) CPAN is just a Perl module, just like any other Perl module. It almost seems like you maybe think you have to run a local CPAN mirror to use the cpan shell. You don't.

        Each module I was trying to install is a single .pm file, no package, no Makefiles, etc. just a single .pm file.

        Then you're not downloading the distribution correctly from the CPAN website. All (or as near as makes no difference) of the distributions available there are tar-balls that contain a Makefile.PL to install with. Search for the module to install on the website I linked (eg, Term::ReadKey, Crypt::Passwd, or Digest::MD5), click the distribution link (the smaller link underneath the main module name), and click the Download link on that page. You will get the .tar.gz file which contains the Makefile.PL. See the other comments in this thread on how to install from there (including sauoq's suggestion on using PREFIX).

        bbfu
        Black flowers blossom
        Fearless on my breath

Re: Problem with DynaLoader and "use"ing downloaded modules
by simonm (Vicar) on Jul 24, 2003 at 23:06 UTC

    Many Perl modules require some kind of dynamically-loaded "extras" in addition to the main *.pm files.

    These may be C code that's compiled into an .SO (or local equivalent) and loaded by something called DynaLoader, or else they may be little snippets of Perl code that are split off into separate files by tools called AutoSplit and AutoLoader.

    Regardless of what kind of "extras" are involved, almost all distributions support a standard series of commands, which will result in all of the necessary bits being set up as they should be.

    From a Unix-like shell command prompt, the typical sequence is as follows:

    # cd Foo-Bar-1.0/ # perl Makefile.PL # make # make test # make install

    If you're retrieving modules from CPAN, you can also use the CPAN shell, which makes this even easier: perl -MCPAN -e 'install Foo::Bar'

      Quote:
      Many Perl modules require some kind of dynamically-loaded "extras" in addition to the main *.pm files.

      These may be C code that's compiled into an .SO (or local equivalent) and loaded by something called DynaLoader, or else they may be little snippets of Perl code that are split off into separate files by tools called AutoSplit and AutoLoader.

      So if DynaLoader is where the error is occuring, does that mean @INC needs to include the path to where the shared library files (.so) are located and not just where the Perl .pm files are?

      Update:
      I found the answer to my own question (with some help from bbfu). To help any other newbies who may face the same problem in the future, the needed libraries are included when "make" is run on the package, and don't need to be included in @INC once the module has been successfully installed on the system (see above post for more info on how my problem was solved).