#!/usr/bin/perl

# $sum = MD5_md5_checksum_file( $file )
sub MD5_md5_checksum_file {
    use MD5; # From the CPAN, http://www.perl.com/CPAN/modules

    my $file = shift;
    open SUM, "<$file" or die "Cannot open $file ($!)";

    # Compute the sum of the entire file at once.
    my $context = MD5->new;
    $context->addfile(SUM);

    # Convert to displayable form.
    return $context->hexdigest();
}

$file = shift;
print MD5_md5_checksum_file($file), "\n";

__END__

# $sum = SSL_md5_checksum_file( $file )
sub SSL_md5_checksum_file {
    use SSLeay;  # From the CPAN, http://www.perl.com/CPAN/modules

    my $file = shift;
    open SUM, "<$file"
        or die "Cannot open $file ($!)";

    # Compute the sum of the file.
    my $md = SSLeay::MD->new("md5");
    while( <SUM> ) {
        # Has to be done one part at a time.
        $md->update($_);
    }

    # Convert to displayable form.
    return unpack("H*",$md->final);
}
