use strict;my $doc = open(my $fileHandler,"<","test.txt");while(my $line = <$fileHandler>) { ## right here I want to look at the next line to see if ## $line =~ m/>/ where > denotes a new entry}解决方法 处理这些问题的一个好方法是使用
Tie::File
,它允许您将文件视为数组,而不会将文件实际加载到内存中.它也是perl v5.7.3以来的核心模块. use TIE::file;tIE my @file,'TIE::file',"test.txt" or dIE $!;for my $linenr (0 .. $#file) { # loop over line numbers if ($file[$linenr] =~ /foo/) { # this is the current line if ($file[$linenr + 1] =~ /^>/ && # this is the next line $linenr <= $#file) { # don't go past end of file # do stuff } }}untIE @file; # all done总结
以上是内存溢出为你收集整理的如何查看Perl中文件的下一行全部内容,希望文章能够帮你解决如何查看Perl中文件的下一行所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)