Hash of arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sally123
    New Member
    • Mar 2012
    • 3

    Hash of arrays

    I want to compare 2 hashes of arrays in the following manner:

    Example:
    %hoa=(A1=>[UP1,UP3,UP6],
    A2=>[UP1,UP6],
    A3=>[UP2,UP10],
    );
    %hoadip=(UP1=>[UP2,UP3,UP7],
    UP2=>[UP10,UP9,UP3],
    UP5=>[UP1,UP11],
    );
    Question:
    1. Compare the values of %hoa with the keys of %hoadip
    2. Then for each key matched, compare the values of the 2 hashes of arrays
    3. Print the matching values
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    I think this thread, from here on Bytes.com, will provide the answer that you are looking for.

    Regards,

    Jeff

    Comment

    • sally123
      New Member
      • Mar 2012
      • 3

      #3
      Hello,
      The thread you recommended does not directly answer my question. I hope you will be able to help me.

      The programming language I am using is perl.

      I have the following:
      %a=(A1=>[UP1,UP3,UP6],
      A2=>[UP1,UP6],
      A3=>[UP2,UP10],
      );

      %b=(UP1=>[UP2,UP3,UP7],
      UP2=>[UP10,UP9,UP3],
      UP5=>[UP1,UP11],
      );

      Please keep in mind that the keys are different, so I can't compare them.

      Desired output:
      A1 has values UP1, UP3, UP6.
      Among these, only UP1 is a key in %b.
      The values of UP1 are UP2, UP3, UP7. I have to compare these 3 values with the values in %a. Whichever key in %a has any of these values, I have to print them.

      Example: A1 has UP1, UP3, UP6. UP1 key has values UP2, UP3, UP7. Among these, UP2 has the key A3 and UP3 has the key A1.
      So output is: A1-A3,A1.

      I hope this explanation is clear. Please let me know if there are any doubts.

      Comment

      • chorny
        Recognized Expert New Member
        • Jan 2008
        • 80

        #4
        At least for me it is not clear. Write an algorithm, not an example. IMHO, you should use foreach or each.

        Comment

        Working...