lightoverhead has asked for the wisdom of the Perl Monks concerning the following question:
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.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 {......} } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to reset the input operater in while loop?
by GrandFather (Saint) on Sep 30, 2008 at 05:49 UTC | |
by lightoverhead (Pilgrim) on Sep 30, 2008 at 07:06 UTC | |
by GrandFather (Saint) on Sep 30, 2008 at 09:34 UTC | |
by graff (Chancellor) on Oct 01, 2008 at 04:13 UTC | |
by graff (Chancellor) on Oct 01, 2008 at 04:27 UTC | |
|
Re: how to reset the input operater in while loop?
by JavaFan (Canon) on Sep 30, 2008 at 07:09 UTC | |
by AnomalousMonk (Archbishop) on Sep 30, 2008 at 07:51 UTC | |
by JadeNB (Chaplain) on Sep 30, 2008 at 18:51 UTC | |
by JavaFan (Canon) on Sep 30, 2008 at 21:24 UTC |