On Fri, 1 Nov 2002 12:53:41 -0500 (EST), Andy Dougherty wrote:

>At the moment, the bytecode "fingerprint" is built with Digest::MD5.
>Alas, Digest::MD5 wasn't standard with perl versions prior to 5.8.0.
>What should happen in those cases?  Anybody have any good ideas?

Something like this? (untested, possibly slow):

my $fingerprint = join "\n", map {
  join '_', $_->{NAME}, @{$_->{ARGS}}
} @$Parrot::OpLib::core::ops;

if (eval {require Digest::MD5}) {
    $fingerprint = Digest::MD5::md5_hex $fingerprint;
}
else {
    $fingerprint = unpack "%32C*", $fingerprint;
}

From `perldoc -f unpack`:
        In addition to fields allowed in pack(), you may prefix a 
        field with a %<number> to indicate that you want a <number>-
        bit checksum of the items instead of the items themselves. 
        Default is a 16-bit checksum. Checksum is calculated by 
        summing numeric values of expanded values (for string fields 
        the sum of ord($char) is taken, for bit fields the sum of 
        zeroes and ones).

        For example, the following computes the same number as the 
        System V sum program:
        $checksum = do {
                local $/;  # slurp!
                unpack("%32C*",<>) % 65535;
        };


Hope this helps,
Bruce Gray

Reply via email to