The module suggested by AppleFritter is certainly the easiest way.

But in case you want to do it yourself in pure Perl without using a module, the most idiomatic way to do it is probably to use a hash (or two hashes in this case). This command-line script (re-using AppleFritter sample data) should give you a gist on how to do it:

$ perl -E ' my %hash1 = ("abc" => [1, 2, 3, 4]); my %hash2 = ("abc" => [1, 3, 5, 7]); my %val1 = map {$_, 1} @{$hash1{abc}}; my %val2 = map {$_, 1} @{$hash2{abc}}; say "Values missing in hash2: ", join " ", grep {not exists $val2{$_}} + keys %val1; say "Values missing in hash1: ", join " ", grep {not exists $val1{$_}} + keys %val2; ' Values missing in hash2: 4 2 Values missing in hash1: 7 5
Please ask if there is something you don't understand.

Edit: I had not seen j0se's solution when I suggested mine. Although the two solutions look very different, they are based on exactly the same ideas. I probably would not have posted anything if I had seen j0se's post before. Now it is done, I leave the post, it shows at least that, really, TIMTOWTDI in Perl.

(BTW, j0se, I have spent at least 18 weeks in your country, specifically in Bratislava, working for Orange Slovakia back in 2008 (preparing the Euro transition), and also 6 or 7 more weeks a few years before. And, long before, I also visited Bratislava as a young tourist back in 1975, in a totally different and quite difficult political context. Nice city and very nice people. Sorry for the off-topic digression.)


In reply to Re: Comparing 2 hash tables where values are stored in arrays by Laurent_R
in thread Comparing 2 hash tables where values are stored in arrays by jumpingmonkey

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.