Skip Menu |

This queue is for tickets about the Hash-MD5 CPAN distribution.

Report information
The Basics
Id: 107027
Status: open
Priority: 0/
Queue: Hash-MD5

People
Owner: MZIESCHA [...] cpan.org
Requestors: BOBMATH [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.07
Fixed in: (no value)



Subject: hash values not stable
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
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);
Am Fr 11. Sep 2015, 13:58:32, ETHER schrieb: Show quoted text
> > 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);
Thank you very much. The seccond way is exactly what I want to do. I tried to use as less external packages as possible.
On Fri Sep 11 13:58:32 2015, ETHER wrote: Show quoted text
> my $sum = md5_hex(Data::Dumper->new([ $a ])->Indent(0)->Terse(1)-
> >Deparse(1)->Sortkeys(1)->Dump);
The irritating thing about both Dumper and JSON is that they sometimes put numbers in quotes, and sometimes not. print Dumper(10 + 1, 1 . 1) $VAR1 = 11; $VAR2 = '11';
On 2015-09-11 16:00:02, BOBMATH wrote: Show quoted text
> On Fri Sep 11 13:58:32 2015, ETHER wrote:
> > my $sum = md5_hex(Data::Dumper->new([ $a ])->Indent(0)->Terse(1)-
> > > Deparse(1)->Sortkeys(1)->Dump);
> > The irritating thing about both Dumper and JSON is that they sometimes > put numbers in quotes, and sometimes not. > > print Dumper(10 + 1, 1 . 1) > > $VAR1 = 11; > $VAR2 = '11';
Or Data::Dumper output differs related whether XS can be used or not: $ perl -MData::Dumper -e 'warn Data::Dumper->new(["1"],[])->Useperl(1)->Dump' $VAR1 = 1; $ perl -MData::Dumper -e 'warn Data::Dumper->new(["1"],[])->Useperl(0)->Dump' $VAR1 = '1';