On 2015-09-10 21:09:45, BOBMATH wrote:
Show quoted text> Produces a different hash result from the same input.
>
> use strict;
> use warnings;
> use Hash::MD5 qw( sum_hash );
> my $a = { b=>{} };
> print sum_hash($a), "\n"; # e0cd3f16f9e883ca91c2a4c24f47b3d9
> print sum_hash($a), "\n"; # c4ca4238a0b923820dcc509a6f75849b
wouldn't this solve all the problems?
use JSON::MaybeXS; # supports all JSON backends, including those in core
use Digest::MD5 qw(md5_hex); # in core
my $sum = md5_hex(JSON()->new(canonical => 1)->encode($a));
or, using only core modules, and will also support data types that JSON does not (e.g. coderefs, globs, scalarrefs):
use Data::Dumper; # in core
use Digest::MD5 qw(md5_hex); # in core
my $sum = md5_hex(Data::Dumper->new([ $a ])->Indent(0)->Terse(1)->Deparse(1)->Sortkeys(1)->Dump);