in reply to Extract the common values in hash of array with double keys

would like to know whether it is working or not.
Only you know if your code is working the way you want it to work. I don't follow your description of your requirements. That being said, the following looks suspicious:
my ($id, $sum, $haploStr) = split ('\t',$_); push @{$data{$id}{$sum}}, \$haploStr;
Your data structure is a hash of hashes of ... scalar references. Did you really want a hash of hashes of arrays?
my ($id, $sum, @haploStr) = split ('\t',$_); push @{$data{$id}{$sum}}, \@haploStr;
Use Data::Dumper after your while loop to get a better idea of what I'm taking about:
print Dumper(\%data);
I am using "undef" to remove the pattern which is matching (while iterating -- which I think is not good way of programing,
I agree that using undef seems unconventional here. Perhaps you want to delete?

Replies are listed 'Best First'.
Re^2: Extract the common values in hash of array with double keys
by snape (Pilgrim) on Feb 04, 2010 at 19:53 UTC

    delete won't work as it will give me a run time error that the free space is being encountered after deleting the element during iteration

      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