use strict;
use vars qw($VERSION @ISA @EXPORT_OK);
-$VERSION = '2.51';
+$VERSION = '2.53';
require Exporter;
*import = \&Exporter::import;
require Digest::Perl::MD5;
Digest::Perl::MD5->import(qw(md5 md5_hex md5_base64));
- push(@ISA, "Digest::Perl::MD5"); # make OO interface work
+ unshift(@ISA, "Digest::Perl::MD5"); # make OO interface work
};
if ($@) {
# restore the original error
$ctx = Digest::MD5->new;
$ctx->add($data);
- $ctx->addfile(*FILE);
+ $ctx->addfile($file_handle);
$digest = $ctx->digest;
$digest = $ctx->hexdigest;
print "Digest is $digest\n";
-With OO style you can break the message arbitrary. This means that we
+With OO style, you can break the message arbitrarily. This means that we
are no longer limited to have space for the whole message in memory, i.e.
we can handle messages of any size.
use Digest::MD5;
- my $file = shift || "/etc/passwd";
- open(FILE, $file) or die "Can't open '$file': $!";
- binmode(FILE);
+ my $filename = shift || "/etc/passwd";
+ open (my $fh, '<', $filename) or die "Can't open '$filename': $!";
+ binmode($fh);
$md5 = Digest::MD5->new;
- while (<FILE>) {
+ while (<$fh>) {
$md5->add($_);
}
- close(FILE);
- print $md5->b64digest, " $file\n";
+ close($fh);
+ print $md5->b64digest, " $filename\n";
Or we can use the addfile method for more efficient reading of
the file:
use Digest::MD5;
- my $file = shift || "/etc/passwd";
- open(FILE, $file) or die "Can't open '$file': $!";
- binmode(FILE);
+ my $filename = shift || "/etc/passwd";
+ open (my $fh, '<', $filename) or die "Can't open '$filename': $!";
+ binmode ($fh);
- print Digest::MD5->new->addfile(*FILE)->hexdigest, " $file\n";
+ print Digest::MD5->new->addfile($fh)->hexdigest, " $filename\n";
-Perl 5.8 support Unicode characters in strings. Since the MD5
-algorithm is only defined for strings of bytes, it can not be used on
-strings that contains chars with ordinal number above 255. The MD5
-functions and methods will croak if you try to feed them such input
-data:
+Since the MD5 algorithm is only defined for strings of bytes, it can not be
+used on strings that contains chars with ordinal number above 255 (Unicode
+strings). The MD5 functions and methods will croak if you try to feed them
+such input data:
use Digest::MD5 qw(md5_hex);