如何打破Perl的循环? [英] How do I break out of a loop in Perl?
本文介绍了如何打破Perl的循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在for
循环中使用break
语句,但是由于我也在Perl代码中使用了严格的subs,因此出现错误提示:
I'm trying to use a break
statement in a for
loop, but since I'm also using strict subs in my Perl code, I'm getting an error saying:
不允许在 ./final.pl使用的严格限制" 154行.
Bareword "break" not allowed while "strict subs" in use at ./final.pl line 154.
是否有解决此问题的方法(除了禁用严格的Subs之外)?
Is there a workaround for this (besides disabling strict subs)?
我的代码格式如下:
for my $entry (@array){
if ($string eq "text"){
break;
}
}
推荐答案
哦,我找到了.您使用 last 而不是
Oh, I found it. You use last instead of break
for my $entry (@array){
if ($string eq "text"){
last;
}
}
这篇关于如何打破Perl的循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文