Hi Monks, I am just puzzled about how to reset the <> operator in while loop. For example, I have two levels loops like this:
while (<FILE1>){ chomp; my @array1=split; my $a1=$array1[1]; my $a2=$array1[2]; ...... while (<FILE2>){ #wrong, cannot iterate all the lines my @array2=split; my $b1=$array2[0]; my $b2=$array2[1]; if ($a1 eq $b1){ .......} else {......} } }
The problem for the above code is that it cannot iterate all the lines of file2. When the first level of while start its second line, the <> operater of the second level while was already at the end of the file2. Of course I can use "for" loops instead of second while loop. But is there a method that I can reset the position of <> operator and make it to re-iterate the file2 for every line of file1(the first while loop)? Thank you.

In reply to 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.