BEGIN { require UNIVERSAL; *isa= \&UNIVERSAL::isa; } sub Compare { my( $ctx )= 3==@_ ? pop(@_) : {}; my( $x, $y )= \( @_ ); return 0 if defined($$x) != defined($$y); return 0 if ref($$x) ne ref($$y); return $$x eq $$y if ! ref($$x); return 1 if $$x == $$y || $ctx->{0+$$x,0+$$y} || $ctx->{0+$$y,0+$$x}++; return Compare($$$x,$$$y,$ctx) if isa($$x,'SCALAR') || isa($$x,'REF'); if( isa($$x,'ARRAY') ) { return 0 if @$$x != @$$y; for my $idx ( 0..$#$$x ) { return 0 if ! Compare($$x->[$idx],$$y->[$idx],$ctx); } return 1; } if( isa($$x,'HASH') ) { return 0 if keys %$$x != keys %$$y; for my $key ( keys %$$x ) { return 0 unless exists $$y->{$key} && Compare($$x->{$key},$$y->{$key},$ctx); } return 1; } require Carp; Carp::croak( "Unsupported data type (",ref($$x),")" ); }