in reply to Comparing unordered hierarchical arrays
Update: I misread your post. Sorry.
This might be a little quicker as it avoids the sorting
#! perl -slw use strict; sub cmpAoAs{ my( $a, $b ) = @_; my %h; $h{ $_ }++ for map{ @$_ } @$a; $h{ $_ }-- for map{ @$_ } @$b; return 0 == grep{ $_ } values %h; } my $ha = [ [1,2], [5,5,5], [1,2], [3,4] ]; my $hb = [ [4,3], [1,2], [2,1], [5,5,5] ]; print 'Same' if cmpAoAs $ha, $hb; __END__ P:\test>342841 Same
However, on the surface of what you've told us, it loooks a little like your using the wrong structure if only the presence and count of a value (rather than it's position) determine equivalence. But I realise that I am not party to the full sp on your application:)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Comparing unordered hierarchical arrays
by Zaxo (Archbishop) on Apr 06, 2004 at 06:47 UTC | |
|
Re: Re: Comparing unordered hierarchical arrays
by ant9000 (Monk) on Apr 06, 2004 at 06:51 UTC |