On Mon, May 07, 2001 at 08:39:42PM -0700, Stewart Leicester wrote:
> I give up...in the last example, why should they ever compare different?
>
In this example, the two hashes compare different because $a{EXTRA}
contains a reference to %b, while $b{EXTRA} contains a reference to %a, and
those two references are different.
> >This approach also works for comparing hashes. Here
> >we'll demonstrate two different answers:
> >
> > use FreezeThaw qw(cmpStr cmpStrHard);
> >
> > %a = %b = ( "this" => "that", "extra" => [ "more", "stuff" ] );
> > $a{EXTRA} = \%b;
> > $b{EXTRA} = \%a;
> >
> > printf "a and b contain %s hashes\n",
> > cmpStr(\%a, \%b) == 0 ? "the same" : "different";
> >
> > printf "a and b contain %s hashes\n",
> > cmpStrHard(\%a, \%b) == 0 ? "the same" : "different";
> >
> >
> >The first reports that both those the hashes contain the same data,
> >while the second reports that they do not. Which you prefer is left as
> >an exercise to the reader.