CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Re: [1arryb] Digest::MD5::digest woes: Edit Log



FishMonger
Veteran / Moderator

Feb 23, 2009, 10:53 AM


Views: 8234
Re: [1arryb] Digest::MD5::digest woes


Code
#!/usr/bin/perl 

use strict;
use warnings;

use Digest::MD5;

my $file = $ARGV[0];
open (my $IN, "<$file") or die "can't open $file";
binmode $IN;

# get a reference digest string.
my $refhex = `md5sum $file`;
chomp($refhex);
print "md5sum: $refhex\n";

my $md5obj = Digest::MD5->new;
$md5obj->addfile($IN);

# Get the digest hex string from Digest::MD5.
my $hexdigest1 = $md5obj->hexdigest;
print "hexdig1: $hexdigest1\n";

# Get the binary digest from Digest::MD5
print "[calling Digest::MD5::digest]\n";
my $digest1 = $md5obj->digest;
print "digest1: $digest1\n";


seek $IN, 0,0;
$md5obj->reset;
$md5obj->addfile($IN);

my $hexdigest2 = $md5obj->hexdigest;
print "hexdig2: $hexdigest2\n";

# but the digest method seems to return the same value each time.
my $digest2 = $md5obj->digest;
print "digest2: $digest2\n";
print "[internal digest is stable call to call]\n" if $digest1 eq $digest2;



(This post was edited by FishMonger on Feb 23, 2009, 10:54 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Feb 23, 2009, 10:54 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives