First, it really, really helps readability to indent your code. It's hard to see loops when they're flattened out.

Second, it really, really helps to state your problem clearly.

in temp.txt(output), every value of $check1 (rep. by 300)in every line is the same as the value of $check1 on the first line of file1.txt, like...
doesn't tell me what you expect to have happen (well, it sort of does, but not unambiguously), and it doesn't tell me what symptoms you're seeing.

What you have set up is a loop to read F2 inside of a loop to read F1. That is, you read one record from F1, then all records from F2. If there's a second record in F1, you won't read any records from F2 unless you rewind it (seek back to the beginning of the file) first.

Another problem is that a trailing newline is retained in both $check1 and $check2, which is going to screw up the records you're printing. To get rid of them, use chomp(), as in

while ( <F1> ) { chomp; ... split ...

In reply to Re: need help with a bug by dws
in thread Unexpected output from while loop (was: need help with a bug) by Anonymous Monk

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.