我想知道如何在Perl中实现它:
while ( not the end of the files ) $var1 = read a line from file 1 $var2 = read a line from file 2 # operate on variables end while
我不确定如何在一个while循环中从两个文件一次读取一行.
解决方法
好像你自己写了几乎所有的答案.只需检查两个文件句柄的eof,如下所示:
while (not eof $fh1 and not eof $fh2) { my $var1 = <$fh1>; my $var2 = <$fh2>; # do stuff }
更多阅读: