打开文件句柄中的Perl读取小节
我已使用以下方法打开文件:打开文件句柄中的Perl读取小节,perl,filehandle,Perl,Filehandle,我已使用以下方法打开文件: open (FH, "<".$File::Find::name) or die "cannot open file \"".$File::Find::name." \"!"; while (<FH>) { ...my code... } open(FH),我可以想出几种方法来回答这个问题,但我会选择以下答案: while(){ 如果(/^StartSection$/../^EndSection/){ …特殊代码。。。 }否则{ …常规代码。
open (FH, "<".$File::Find::name) or die "cannot open file \"".$File::Find::name." \"!";
while (<FH>) {
...my code...
}
open(FH),我可以想出几种方法来回答这个问题,但我会选择以下答案:
while(){
如果(/^StartSection$/../^EndSection/){
…特殊代码。。。
}否则{
…常规代码。。。
}
}
代码将如何读取if部分的下一行?单词是“Perl”和“file handle”,而不是“Perl”和“FileHandler”。最好使用打开我的$fh,'
open (FH, "<".$File::Find::name) or die "cannot open file
\"".$File::Find::name." \"!";
while (<FH>) {
...my code...
if (/^StartSection$/) {
while (<FH> !~ /^EndSection) {
... more code....
}
}
}
while (<FH>) {
if (/^StartSection$/ .. /^EndSection/) {
... special code ...
} else {
... regular code ...
}
}