Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: recursively comparing heterogenous data structures

by bikeNomad (Priest)
on Jul 07, 2001 at 22:01 UTC ( #94749=note: print w/replies, xml ) Need Help??

in reply to recursively comparing heterogenous data structures

Another way to compare arbitrary data structures (if you just need to see if they're different, and don't care about CODE or GLOB reference differences internally):

use Storable; $Storable::canonical = 1; my compare { Storable::freeze($_[0]) eq Storable::freeze($_[1]) }

update:The above gets hashes right (by sorting their keys); however, it doesn't allow ignoring ordering of lists as the original code does.

Replies are listed 'Best First'.
Re: Re: recursively comparing heterogenous data structures
by thraxil (Prior) on Jul 08, 2001 at 01:31 UTC

    that's pretty useful. unfortunately, it is order dependent. i wrote the code above because i had data structures to compare and i didn't care about the order of any lists within; just whether or not they had the same elements.

    anders pearson

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://94749]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-05-16 15:27 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (63 votes). Check out past polls.