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

Here's how I'm trying to use MD5:
use Digest::MD5; my $md5 = Digest::MD5->new; $md5->add(localtime,"%ENV",rand(500)); $mls = $md5->hexdigest();
Here's the error I get:
Can't locate loadable object for module MD5 in @INC (@INC contains: .. +/ d:/Perl/lib d:/Perl/site/lib) at d:\PROGRA~1\APACHE~1\apache\cgi-bi +n\admin\manager.cgi line 117 Compilation failed in require at d:\PROGRA~1\APACHE~1\apache\cgi-bin\a +dmin\manager.cgi line 117. BEGIN failed--compilation aborted at d:\PROGRA~1\APACHE~1\apache\cgi-b +in\admin\manager.cgi line 117.
I've used this exact same code under Perl 5.6 and 5.8 with the same error. I've not tried to install it manually or anything and when using PPM to try to update it, I get a message telling me that I've already got the latest version installed. Any ideas what I'm doing wrong?

Replies are listed 'Best First'.
Re: Problem using Digest::MD5
by tachyon (Chancellor) on Jan 03, 2003 at 09:24 UTC

    Your code runs fine on my Win2K machine with MD5 installed. I would do a reinstall. Download the Digest-MD5.zip file from AS here unzip it to a tmp dir, navigate there and and:

    C:\tmp>ppm install Digest-MD5.ppd

    ppm will not complain about it already being installed and will reinstall it if you do it this way. Normally you could do a ppm remove Some-Package but ppm needs Digest-MD5 so it won't let you.

    I presume you don't have more than one version of Perl installed and you have not say changed drive letters or installed new devices and had Win32 do it for you? Is this from the apache error logs or do you get the same result from the command line?

    This is the .packlist in C:\Perl\site\lib\auto\Digest\MD5 which should be the same on your box (D:)

    C:\Perl\site\lib\Digest.pm C:\Perl\site\lib\Digest\HMAC.pm C:\Perl\site\lib\Digest\HMAC_MD5.pm C:\Perl\site\lib\Digest\HMAC_SHA1.pm C:\Perl\site\lib\Digest\MD2.pm C:\Perl\site\lib\Digest\MD5.pm C:\Perl\site\lib\Digest\SHA1.pm C:\Perl\site\lib\MD5.pm C:\Perl\site\lib\SHA.pm C:\Perl\site\lib\auto\Digest\MD2\MD2.bs C:\Perl\site\lib\auto\Digest\MD2\MD2.dll C:\Perl\site\lib\auto\Digest\MD2\MD2.exp C:\Perl\site\lib\auto\Digest\MD2\MD2.lib C:\Perl\site\lib\auto\Digest\MD5\MD5.bs C:\Perl\site\lib\auto\Digest\MD5\MD5.dll C:\Perl\site\lib\auto\Digest\MD5\MD5.exp C:\Perl\site\lib\auto\Digest\MD5\MD5.lib C:\Perl\site\lib\auto\Digest\SHA1\SHA1.bs C:\Perl\site\lib\auto\Digest\SHA1\SHA1.dll C:\Perl\site\lib\auto\Digest\SHA1\SHA1.exp C:\Perl\site\lib\auto\Digest\SHA1\SHA1.lib

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Problem using Digest::MD5
by grinder (Bishop) on Jan 03, 2003 at 09:32 UTC

    The code posted works perfectly here with Perl 5.6.1. It sounds as if the module is not installed. I would expect you would find the .pm file at d:/Perl/site/lib/Digest/MD5.pm. Is this the case? If so, you will find the loadable file (a DLL) at d:/Perl/site/lib/auto/Digest/MD5.dll. If this is not the case then I'd say your installation is a bit broken.

    A few points about the code: "%ENV" will not interpolate. You want to do something like join( '', %ENV ). A second problem is that rand(500) doesn't give you much randomness, a shade under 9 bits. You want to generate at least 128 bits of randomness. Try something like:

    my $x; $x .= chr(rand(255)) for 1 .. 16; # or more

    This, of course, is only as good as your random number generator, but that's another story.

    b64digest is a more compact representation of the digest than hexdigest, which might be useful since I imagine you are trying to generate session IDs. But hey, in that case, why not use something that has already been written, and, as a free bonus, has been scrutinised by a cast of thousands, namely Apache::Session.


    print@_{sort keys %_},$/if%_=split//,'= & *a?b:e\f/h^h!j+n,o@o;r$s-t%t#u'
Re: Problem using Digest::MD5
by PodMaster (Abbot) on Jan 03, 2003 at 09:26 UTC
    You have a botched install of MD5. Uninstall it, and reinstall it, or simply reinstall it.

    You should read up on your PPM documentation, it's there so you know how to use PPM.

    ppm> install -force Digest-MD5


    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    ** The Third rule of perl club is a statement of fact: pod is sexy.

      Don't know what documentation you have or what version of ppm but -force is not an option on my system, nor is it in the docs for that matter

      Microsoft Windows 2000 [Version 5.00.2195] (C) Copyright 1985-2000 Microsoft Corp. C:\>ppm install -force Digest-MD5 Unknown option: force Version 2.09 of 'Digest-MD5' is already installed. Remove it, or use 'verify --upgrade Digest-MD5'. C:\>ppm install --force Digest-MD5 Unknown option: force Version 2.09 of 'Digest-MD5' is already installed. Remove it, or use 'verify --upgrade Digest-MD5'. C:\>ppm PPM interactive shell (2.1.5) - type 'help' for available commands. PPM> install -force Digest-MD5 Unknown option: force Version 2.09 of 'Digest-MD5' is already installed. Remove it, or use 'verify --upgrade Digest-MD5'. PPM> install --force Digest-MD5 Unknown option: force Version 2.09 of 'Digest-MD5' is already installed. Remove it, or use 'verify --upgrade Digest-MD5'. PPM> verify --upgrade Digest-MD5 Upgrade package 'Digest-MD5'? (y/N): y This hangs forever......... and needs a ^C to escape

      A Digest-MD5.zip -> D-M.ppd -> ppm install D-M.ppd does force a reinstall which as you say is needed.

      cheers

      tachyon

      s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

        That's why my first piece of advice was uninstall, then reinstall.

        Both ActivePerl 5.6 and 5.8 come with ppm3, and that is a ppm3 option. You don't need the any of the PPM shells to install ppm packages using PPM. PPM is also a module.

        update: also, you don't need PPM to uninstall modules. See ExtUtils::Installed and `perldoc -f unlink'.

        I so cannot wait for the CPANPLUS shell to integrate PPM support (there is a backend, well in CVS)


        MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
        ** The Third rule of perl club is a statement of fact: pod is sexy.