in reply to Comparing unordered hierarchical arrays

Your idea of sorting first and then comparing is exactly right. There may be a cleverer way, but I don't know what it might be.

Your "serialization" hack is probably not satisfactory. You will need iterative sort and comparison for this to work for arbitrary nested arrays. Recursion is an attractive way of writing that for not-too-deep nesting.

After Compline,
Zaxo

  • Comment on Re: Comparing unordered hierarchical arrays

Replies are listed 'Best First'.
Re: Re: Comparing unordered hierarchical arrays
by jdporter (Paladin) on Apr 06, 2004 at 13:50 UTC
    Like this:
    sub serialize { my $r = shift; ref $r ? '(' . join( ',', sort map serialize($_), @$r ) . ')' +: $r } sub deep_eq { my( $x, $y ) = @_; serialize($x) eq serialize($y) }

    jdporter
    The 6th Rule of Perl Club is -- There is no Rule #6.