in reply to Comparing unordered hierarchical arrays
Note that it only handles AoA, and theres some ugly repeated code (the two for loops that sort the temporary array refs ), and basically no error checking. But it does seem to work =].use strict; my $ha = [[1,2], [5,5,5], [1,2], [3,4]]; my $hb = [[4,3], [2,1], [1,2], [5,5,5]]; sub test { my ($ha, $hb) = @_; my ($tha,$thb) = ([],[]); for( @{ $ha } ) { push @{$tha},[ sort @{$_} ]; } $tha = [ sort { $a->[0] <=> $b->[0] } @{$tha} ]; for( @{ $hb } ) { push @{$thb},[ sort @{$_} ]; } $thb = [ sort { $a->[0] <=> $b->[0] } @{$thb} ]; use Data::Dumper; return Dumper($tha) eq Dumper($thb); } print test($ha,$hb);
|
|---|