On Fri, Jan 9, 2009 at 16:40, Mike McClain <mmcclain@xxxxxxxxxxx> wrote:
> I appreciate your taking the time to respond and having been
> reading your responses for several months now have no doubt that
> you know what you're talking about.
> I'm still not clear however about what's going on.
> As you can see from the above calculations what's being returned
> by Digest::MD5->md5_hex is neither the md5 sum of the module nor the
> concatenation of the module and the argument (my file md5_hex).
> Would you mind explaining further or pointing me to further reading
> that might straighten out this feeble old mind?
You seem to be under the impression that the argument to
Digest::MD5::md5_hex is a file name. The argument is a scalar holding
the data to perform md5 on. So Digest::MD5::md5_hex("foo") will give
you the MD5 of the data "foo". When you say
Digest::MD5->md5_hex("foo") you are really saying
Digest::MD5::md5_hex("Digest::MD5", "foo") so you will get the MD5 of
the string "Digest::MD5" concatenated with the string "foo". If you
want to perform an MD5 on a file you must either get the data from
that file into a scalar or use the objected oriented interface's
addfile method call. The method call is more efficient because the
whole file does not need to be in memory at once (it just reads in one
block at a time).
print "Calling md5_hex with 'Digest::MD5': ",
"Calling md5_hex with 'Digest::MD5' in a different way: ",
"Calling md5_hex with 'Digest::MD5foo': ",
"Calling md5_hex with 'Digest::MD5' and 'foo': ",
#store this file as data in $data
seek DATA, 0, 0;
my $data = join '', <DATA>;
#get an md5 of this file another way:
open my $fh, "<", $0
or die "could not open $0: $!";
my $md5 = Digest::MD5->new;
print "Calling md5_hex on this program: ",
"Calling md5_hex on this program another way: ",
The most important skill a programmer can have is the ability to read.