The first problem is that you are opening the file handles: F1 and F2 for writing. And you specifiy that for example the files named $file1 and $file2 should be deleted and new files should be started with those names - so what you have is basically nonsense code. You can't read a file that you just "zero'ed" with empty contents!

#Maybe this what you mean???? open (F1, '<' ,$file1) or die "Cannot open file $file1 for reading\n"; open (F2, '<', $file2) or die "Cannot open file $file2 for reading\n";
If you are trying to compare or match files on a line by line basis, this can become complex.

What do you want to happen if say file1 has fewer lines than file2?

I didn't test this, but it appears that your "while statement" does:

while ( <F1>, <F2> ) { # throw away a line from file F1 - never to be used # end the loop if there are no more lines in F2 # set $_ to the next line from F2 # <F1> plays no role here - it is a No-Operation: NoOp }
So this simplifies into:
while ( <F2> ) { # $_ is a line from $file2 }
Which I suspect is not what you want. What do you want?

In reply to Re: Reading two text files parallelly... by Marshall
in thread Reading two text files parallelly... by biswanath_c

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.