getting diffent md5 digest when using the same perl script in a windows
xp environment running strawbery perl 5.10 and running the same script
on an RHEL system and another debian system.
*nix system give the same digest, perl on windows does not.
here is the script
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use Data::Dumper;
use XML::Simple;
use XML::LibXML;
use Digest::MD5;
use MIME::Base64;
use File::Basename;
use Getopt::Std;
sub usage {
print STDERR << "EOF";
This program calculates the MD5 checksum of a file and writes it to file
test1.md5
usage: $0 -f FILE
-f : file containing data to be uploaded.
example: $0 -f /tmp/0_20081008T183240_20081008T193245_11_11.txt
EOF
exit;
}
my %opts = ();
my ($uploadfile);
getopts("f:", \%opts) ;
if (defined($opts{f})) {
$uploadfile = $opts{f};
}
else { usage(); }
&calcmd5($uploadfile);
# calculates the md5 of specified file and writes it to a file.
sub calcmd5 {
my ($filename) = @_;
# the rest interface is expecting base64 encoded binary data.
# nothing else is currently supported.
my $encoding = "base64";
my $dataContent;
open FILE, "<", $filename or die "could not open file: $!";
#original md5 calculation
binmode (FILE);
my $md5 = Digest::MD5->new->addfile(*FILE)->hexdigest;
seek(FILE, 0, 0); # return to the beginning of the file.
binmode (FILE);
close FILE or die "could not close file: $!";
#writing calculated md5 to a file called test1.md5
open OUTPUT, ">test1.md5";
print OUTPUT $md5;
close OUTPUT;
}
1;