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

Hi

I am trying to create a script to return the MD5sum of a .exe or .zip .txt etc . I am getting a value returned but it does not correspond to what an off the shelf md5sum calculators returns. Thanks in advance for your help.

.

G

#! c:\\Perl\\bin\\Perl.exe use Digest::MD5 qw(md5_hex); open(FILE, "logs.txt"); my $file = <FILE>; binmode(FILE); $md5_hex = Digest::MD5->new->addfile(*FILE)->hexdigest; close(FILE); print "MD5: " . $md5_hex . "\n";

Replies are listed 'Best First'.
Re: MD5 hex calculation
by talexb (Chancellor) on Apr 24, 2013 at 14:13 UTC

    You probably need to read the documentation -- although, having just looked at the perldoc for Digest::MD5, it's a little opaque.

    You don't need to read anything from the file, or set the binmode .. something like

    #! c:\\Perl\\bin\\Perl.exe use Digest::MD5 qw(md5_hex); open(FILE, "logs.txt"); # YOU NEED ERROR CHECKING HERE $md5_hex = Digest::MD5->new->addfile(FILE)->hexdigest; close(FILE); print "MD5: " . $md5_hex . "\n";
    will probably work fine. I just deleted unnecessary lines from your code.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

      Thank You. I will go and try that and report back. Thanks for your time and help.

      G

        Worked perfectly . Brilliant another piece learned.Thank You

        G
Re: MD5 hex calculation
by Anonymous Monk on Apr 24, 2013 at 14:06 UTC

    Why do you read from the filehandle ??? Why  my $file = <FILE>;???

      I am new to Perl. I am trying to use what I have already picked up by practice.

      G

        I am new to Perl. I am trying to use what I have already picked up by practice.

        So do you go up to a cashier/bartender, rip a five dollar bill in half, and order a drink?