Thank you for your answer. I know this is not the right way to do it. Sorry for this confusion. In fact what I was trying to do is to compare each line of file1 with each line of file2, not just match each other. I had two ways to do it,first,open and close file2 for each line for file1, thus I can iterate all the lines of file2 every time. Second, I can build an array to store items of file1 or file2,then iterate them. Using hash should be fine too. But either way (opening/closing file or array/hash) has its own shortcoming. opening/closing file will be slower (right?),array/hash will consume memory. These two files are very very huge files. I recalled that I might read it somewhere that we could reset the position of <> operator, and every time when one round iteration is done, it might be set back to do another round iteration. I am not sure if this method exists. But if there is one like this, I could be able to re-iterate the file without opening/closing files or building arrays/hashes. Thanks.

In reply to Re^2: how to reset the input operater in while loop? by lightoverhead
in thread how to reset the input operater in while loop? by lightoverhead

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.