You have to change the line to:
delete $data{$key2}{$sum2};

UPDATE: Oops, I think I misunderstood your problem. You might include a check for existence before you access an array value in the loop

if (exists $data{$key1}{$sum1}) { ... # and later if (exists $data{$key2}{$sum2}) { ... # or next if (not exists $data{$key2}{$sum2});

You might even avoid one of the exists-lines if you don't delete the second item (i.e. $data{$key2}{$sum2}) but the original item (i.e. $data{$key1}{$sum1}) and exit the inner loops immediately. If a third identical item is there it will be detected when the second item later becomes an original item. Since you never delete an item that $key1 and $sum1 might encounter later on, you don't need to test $data{$key1}{$sum1} for existence.

Whether your code is correct I can't easily judge (without investing a lot more time). Maybe you should extract your algorithm to a subroutine and the comparision of the two arrays to another subroutine, that would make your program much more readable and testable. Then write some test cases and compare the expected result with what you really get


In reply to Re^3: Extract the common values in hash of array with double keys by jethro
in thread Extract the common values in hash of array with double keys by snape

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.