in reply to Re: reading the wrong input file out of 2 opened file
in thread reading the wrong input file out of 2 opened file

The reads a line from F1 and puts it into $_

wrong

  • Comment on Re^2: reading the wrong input file out of 2 opened file

Replies are listed 'Best First'.
Re^3: reading the wrong input file out of 2 opened file
by Marshall (Canon) on Jan 24, 2022 at 16:58 UTC
    You are correct. This is an artifact of having the logical statement in the conditional. while (<FH>){} does assign the line to $_. However, while (<FH> and some condition){} doesn't assign the read line to $_ only the "truthiness" of whether a line was actually read or not is used (the line itself is thrown away). Ok, we have found yet another reason why this odd looking while statement won't work. while (defined (my $line =<FH>) and some condition){} is perhaps better. It is possible to assign to $_ (left hand side), but I seldom do that. This whole idea of an "and" or "&&" statement in the while condition looks dubious to me.