in reply to How to compare two associative arrays efficiently

I had something similar but it had to do with combinations of arrays... check this post maybe something there could help.

Good luck.

p.s. Add html tags to your posts to make them easier for others to read.
  • Comment on Re: How to compare two associative arrays efficiently

Replies are listed 'Best First'.
Re^2: How to compare two associative arrays efficiently
by viveks_19 (Initiate) on Oct 13, 2006 at 02:49 UTC
    Thank you so much guys for your kind help, I used the solution given by ikegami and it worked very well(and fast) for me. I found my answer and I am closing this thread. Thanks alot once again to all of you.
    my @unique_pssns = grep { not exists $assns{$_} } @pssns; print("The following PSSNs have no corresponding ASSNs:\n"); print("$_\n") foreach @unique_pssns;
      Thank you so much guys for your kind help, I used the solution given by ikegami and it worked very well(and fast) for me. I found my answer and I am closing this thread. Thanks alot once again to all of you.

      You can't (technically) "close" a thread. Indeed you solved your problem and that's fine. Now, one last remark is in order, in the hope that you will benefit from it: comparing your newly found solution

      my @unique_pssns = grep { not exists $assns{$_} } @pssns;

      with your initial attempt the lesson to be learned is that the choice of the data structure does matter in contrast with your assumption that "array or associative array doesn't matter". In particular you had homogeneous data "dispersed" across keys and values of given hashes with no sensible association between each key-value pair. Also, loading data from your flat files into hashes like that also will make you risk of losing some of it (specifically, different values associated to identical keys). For that naive two-loop approach an array would have been better. But when you have to check for existence, as a mnemonic remember of exists and think of a hash. This will get rid of one of the loops. Of course nobody prohibits you to have your main data stored into an array and to create a hash on the fly exactly for this purpose, as per ikegami's solution. As far as the other loop goes, it's still behind the curtain in grep but of course the latter as a higher level tool with a specific application highlights the logic and hides the details, not to mention the keystrokes it saves you.