How do I break out of a loop in Perl

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

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;
    }
}

Answers

Oh, I found it. You use last instead of break

for my $entry (@array){
    if ($string eq "text"){
         last;
    }
}

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/303216/how-do-i-break-out-of-a-loop-in-perl

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils