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:
Bareword "break" not allowed while "strict subs" in use at ./final.pl line 154.
Is there a workaround for this (besides disabling strict subs)?
My code is formatted as follows:
for my $entry (@array){
if ($string eq "text"){
break;
}
}
Simply
last
would work here:If you have nested loops, then
last
will exit from the innermost. Use labels in this case:Given
last
statement will make compiler to come out from both the loops. Same can be done in any number of loops, and labels can be fixed anywhere.Additional data (in case you have more questions):
On a large iteration I like using interrupts. Just press Ctrl + C to quit:
Oh, I found it. You use last instead of break