在Perl中我试图实现这个目标:
while ($row = <$fh>){
if the row contains the character >:
#do something AND then skip to the next line
else:
#continue to parse normally and do other things
Run Code Online (Sandbox Code Playgroud)
您可以使用next内置跳转到循环的下一次迭代.由于您是逐行阅读,所以您需要做的就是这些.
要检查字符是否存在,请使用正则表达式.这是由m//运营商和=~Perl完成的.
while ($row = <$fh>) {
if ( $row =~ m/>/ ) {
# do stuff ...
next;
}
# no need for else
# continue and do other stuff ...
}
Run Code Online (Sandbox Code Playgroud)