in reply to combining hashes based on key values

You've got several smaller chores that add up to the solution to your problem. Tackling the small chores will help you to solve the bigger picture.

In %out_hash, 'jibber jabber' holds those id's that are found in both 'jibber' and in 'jabber'. This is an intersection.

You also want %out_hash to keep the id's from "jibber" that are unique to "jibber" within the key named "jibber", and the same for "jabber". This is the symmetric difference.

You may get a start by looking at List::Compare, and by reading perlfaq4 under the section called "How do I compute the difference of two arrays? How do I compute the intersection of two arrays?" For your purposes, your input hashes are simply sparse arrays. Treat them as lists of id's indexed by hash keys instead of array indices, and you'll find your way around the problem. This response assumes you already know your way around Perl's references and complex datastructures. If you need help tackling those too just let us know where you need clarification.


Dave

  • Comment on Re: combining hashes based on key values

Replies are listed 'Best First'.
Re^2: combining hashes based on key values
by punkish (Priest) on Jun 08, 2005 at 04:09 UTC
    Very sweet. You have set me on the right path... not the shortest path, but the most interesting, meandering, full-of-knowledge path. There seems to be much fun in List::Compare

    Thanks.

    --

    when small people start casting long shadows, it is time to go to bed

      As I look at it again, you're more interested in left complement and right complement than in symmetrical difference, because you're going to need to build a list based on what's only in jibber, a list based on what's only in jabber, and then the intersection (a list based on what's in both jibber and in jabber).

      List::Compare is going to get you most of the way there, if you look at the two input lists as:

      @{$in_hash{jibber}} # Left list @{$in_hash{jabber}} # Right list

      Dave