Skip Menu |
 

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Data-Compare CPAN distribution.

Report information
The Basics
Id: 52836
Status: resolved
Priority: 0/
Queue: Data-Compare

People
Owner: Nobody in particular
Requestors: sharyanto [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.2101
Fixed in: (no value)



Subject: Can't handle recursive/circular structure
Download (untitled) / with headers
text/plain 239b
$ perl -MData::Compare -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=$b; say "equal" if Compare($a, $b)' $ but: $ perl -MStorable=freeze -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}= $b; say "equal" if freeze($a) eq freeze($b)' equal $
Download (untitled) / with headers
text/plain 695b
On Wed Dec 16 12:08:49 2009, SHARYANTO wrote: Show quoted text
> $ perl -MData::Compare -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=$b; > say "equal" if Compare($a, $b)' > $ > > but: > > $ perl -MStorable=freeze -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}= > $b; say "equal" if freeze($a) eq freeze($b)' > equal > $
This comes down to differing interpretations of what data are equivalent. In this case, while the *structures* are equivalent, the data are different, as is evident by stringifying $a->{a} and $b->{a}: $ perl -e '$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=$b; print $a->{a}."\n";print $b->{a}."\n"' HASH(0x812c1c8) HASH(0x812c0e4) I'll add a note to the documentation to make this clear.
Download (untitled) / with headers
text/plain 1.3k
On Mon Feb 01 11:54:12 2010, DCANTRELL wrote: Show quoted text
> On Wed Dec 16 12:08:49 2009, SHARYANTO wrote:
> > $ perl -MData::Compare -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=
$b; Show quoted text
> > say "equal" if Compare($a, $b)' > > $ > > > > but: > > > > $ perl -MStorable=freeze -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->
{a}= Show quoted text
> > $b; say "equal" if freeze($a) eq freeze($b)' > > equal > > $
> > This comes down to differing interpretations of what data are > equivalent. In this case, while the *structures* are equivalent, the > data are different, as is evident by stringifying $a->{a} and $b->{a}: > > $ perl -e '$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=$b; print > $a->{a}."\n";print $b->{a}."\n"' > HASH(0x812c1c8) > HASH(0x812c0e4)
But this works (the two [1] refs don't stringify the same too because they are two copies): $ perl -MData::Compare -le'$a={a=>[1]}; $b={a=>[1]}; print $a->{a}; print $b->{a}; print Compare($a,$b)' ARRAY(0x627df0) ARRAY(0x627c40) 1 As long as the structures are the same and the data values are the same, shouldn't they be considered the same? Isn't that what Data::Compare is all about? Make this analogy: the recursive structure is a circle (or Mobius strip) of 5cm diameter. Shouldn't it also be "comparable" with another circle (or Mobius strip) of 5cm diameter too, even if they are separate?
Download (untitled) / with headers
text/plain 1.8k
On Tue Feb 09 15:21:08 2010, SHARYANTO wrote: Show quoted text
> On Mon Feb 01 11:54:12 2010, DCANTRELL wrote:
> > On Wed Dec 16 12:08:49 2009, SHARYANTO wrote:
> > > $ perl -MData::Compare -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=
> $b;
> > > say "equal" if Compare($a, $b)' > > > $ > > > > > > but: > > > > > > $ perl -MStorable=freeze -E'$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->
> {a}=
> > > $b; say "equal" if freeze($a) eq freeze($b)' > > > equal > > > $
> > > > This comes down to differing interpretations of what data are > > equivalent. In this case, while the *structures* are equivalent, the > > data are different, as is evident by stringifying $a->{a} and $b->{a}: > > > > $ perl -e '$a={c=>1}; $a->{a}=$a; $b={c=>1}; $b->{a}=$b; print > > $a->{a}."\n";print $b->{a}."\n"' > > HASH(0x812c1c8) > > HASH(0x812c0e4)
> > But this works (the two [1] refs don't stringify the same too because > they are two copies): > > $ perl -MData::Compare -le'$a={a=>[1]}; $b={a=>[1]}; print $a->{a}; > print $b->{a}; print Compare($a,$b)' > ARRAY(0x627df0) > ARRAY(0x627c40) > 1 > > As long as the structures are the same and the data values are the > same, shouldn't they be considered the same? Isn't that what > Data::Compare is all about? > > Make this analogy: the recursive structure is a circle (or Mobius > strip) of 5cm diameter. Shouldn't it also be "comparable" with another > circle (or Mobius strip) of 5cm diameter too, even if they are separate?
Ah sorry, my mistake, I answered first without reading the code :-) In the first case, it's failing because it's detected a situation where it might recurse infinitely. There's a special case in the code for that, with a comment "is this the right thing to do?", because at the time I couldn't see a reliable and obviously correct way of proceding. I need to think about this a bit.
Please try this new version of the module
Subject: Compare.pm
Download Compare.pm
text/x-perl 12.2k

Message body is not shown because it is too large.



This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.