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

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.