Hello Monks, I have a hash with numbers as the keys and an array of elements as the values. I also have another hash with the numbers as the keys (these numbers exist in the first hash but numbers in first hash may not exist in second hash) and a number count as the values.
%hash1 = ( 1=> ["You", "Me", "Him", "Her"], 2 => ["You", "Me", "Him", + "Her"], 3 => ["You", "Me", "Him", "Her"], and so on). %hash2 = ( 1 => 3, 51 => 0, 32 => 1, and so on)

I need to loop through hash1, print out its values and also look up the value from the second hash that corresponds to the same key in the first hash and print that value. For example:

If one of the keys from hash1 was 3 and if 3 existed in hash2, you would print the value of 3 from hash1 and the value of 3 in hash2 on the same line.

this is what I have been doing:
foreach my $keys (keys %hash1){ if (defined $hash2{$keys}){ print @{ $hash1{$keys} }, "\t", $hash2{$keys}, "\n";

and it hasn't been printing anything. I hope to get:

You Me Him Her 3

as an example output for the first line

what is wrong with my loop? any help would be great. thanks a lot guys!

In reply to looping through a hash and looking up values from another hash by pearllearner315

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.