Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re: compare an array of hashes

by inman (Curate)
on Mar 09, 2006 at 16:38 UTC ( #535432=note: print w/replies, xml ) Need Help??

in reply to compare an array of hashes

Functions such as each_array and pairwise from List::MoreUtils will allow you to iterate over two lists at a time and process them. This assumes that your lists are similar and you are just trying to get different items.

If your data is key driven then you can use a hash to find the unique keys and then grep them from the list.

my @wanted; my %keys; $keys{$_->{flag}}++ foreach (@array1, @array2); my @unique = grep {$keys{$_->{flag}} == 1} @array2; print Dumper(@unique);

Replies are listed 'Best First'.
Re^2: compare an array of hashes
by Anonymous Monk on Mar 10, 2006 at 13:42 UTC
    This is exactly what I was looking for. How do I get a list of the keys that are common to both ?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://535432]
[thezip]: That's awesome. I bet you feel totally rejuvenated and ready for the next thing.
[stevieb]: A couple of years ago I went to Curacao on a business trip which is a few parallels south of Canary Islands, but one thing I liked was it was 90 degrees at all times consistently. Much different experience than living in Canada :)

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2017-02-23 17:09 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (349 votes). Check out past polls.