在 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
最佳答案
您可以使用 next
built-in 跳到循环的下一次迭代。 .由于您正在逐行阅读,这就是您需要做的全部工作。
要检查字符是否存在,请使用 a regular expression .这是通过 m//
operator 完成的和 =~
在 Perl 中。
while ($row = <$fh>) {
if ( $row =~ m/>/ ) {
# do stuff ...
next;
}
# no need for else
# continue and do other stuff ...
}
关于perl - 如何在 Perl 的 while 循环中跳过迭代步骤?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34087497/