hello, i read one column from two different flat files and stored the result into two associative arrays,
Associative arrays are for associating stuff, specifically keys with values. Now, independently of how you build them, we know that you got two such associative arrays. Supposedly the keys are entries from the first columns of each file, and other info missing one has to guess values are of no particular interest, and thus probably undef.
now I have to comapare these two arrays.
They're not arrays. They're associative arrays aka hashes. How do you want to compare them? Just find common keys?!?
If I use foreach loop, it will be very inefficient as it will loop thru n*n times.
You're saying more now, implying that both hashes have the same size. Indeed a hash must be though of as a mapping which also recalls the naive concept of a set which in turn recalls that of membership, thus it should come as no surprise that membership can be tested by means of straight features hiding the details from the programmer. Specifically chances are you just want to know about exists.
if they dont have common values then I have to store into another array. I am not sure how to do that. can anyone suggest something.
If they don't have common values (which values?!?) you have to store what into what? (really "another array" or another hash?)
In reply to Re: How to compare two associative arrays efficiently
by blazar
in thread How to compare two associative arrays efficiently
by viveks_19
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |