加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Perl中,如何在一个循环中读取多个文件句柄?

发布时间:2020-12-15 21:53:10 所属栏目:大数据 来源:网络整理
导读:我想知道如何在Perl中实现它: while ( not the end of the files ) $var1 = read a line from file 1 $var2 = read a line from file 2 # operate on variablesend while 我不确定如何在一个while循环中从两个文件一次读取一行. 解决方法 好像你自己写了几
我想知道如何在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
}

更多阅读:

> perldoc -f open
> perldoc -f eof
> perldoc perlopentut

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读