繁体   English   中英

如何在Perl中的while循环中跳过迭代步骤?

[英]How do I skip an iteration step in a while loop in Perl?

在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内置命令跳到循环的下一个迭代。 因为您正在逐行阅读,所以这就是您需要做的。

要检查字符是否存在,请使用正则表达式 这是通过m//运算符和Perl中的=~完成的。

while ($row = <$fh>) {
  if ( $row =~ m/>/ ) {
    # do stuff ...
    next;
  }
  # no need for else
  # continue and do other stuff ...
}

尝试这种方式:

while ($row = <$fh>)
{
    if($row =~ />/)
    {
        #do something AND then skip to the next line
        next;
    }
    #continue to parse normally and do other things
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM