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

时间:2015-12-04 11:35:49

标签: 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

2 个答案:

答案 0 :(得分:7)

您可以使用next built-in跳到循环的下一次迭代。既然你是逐行阅读的,那就是你需要做的一切。

要检查角色是否存在,请使用a regular expression。这是通过Perl中的m// operator=~来完成的。

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

答案 1 :(得分:3)

尝试这种方式:

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