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:
Simply last would work here:
for my $entry (@array){
if ($string eq "text"){
last;
}
}
If you have nested loops, then last will exit from the innermost loop. Use labels in this case:
LBL_SCORE: {
for my $entry1 (@array1) {
for my $entry2 (@array2) {
if ($entry1 eq $entry2) { # Or any condition
last LBL_SCORE;
}
}
}
}
Given a last statement will make the compiler to come out from both the loops. The same can be done in any number of loops, and labels can be fixed anywhere.