【发布时间】:2017-08-18 14:01:59
【问题描述】:
我打开了一个文件:
open (FH, "<".$File::Find::name) or die "cannot open file \"".$File::Find::name." \"!";
while (<FH>) {
...my code...
}
我使用正则表达式解析行以获取我想要的数据。 现在我想读取文件的一个小节,直到在我的 while 循环中看到该小节的结尾。 即:逐行从“StartSection”读取到“EndSection”:
open (FH, "<".$File::Find::name) or die "cannot open file
\"".$File::Find::name." \"!";
while (<FH>) {
...my code...
if (/^StartSection$/) {
while (<FH> !~ /^EndSection) {
... more code....
}
}
}
我必须如何在 Perl 中正确编程?
【问题讨论】:
-
单词是“Perl”和“文件句柄”,而不是“PERL”和“FileHandler”。
-
更好用
open my $fh, '<', $filename ...
标签: perl filehandle