Hi Chris,
Use loop breaks such as last, next, goto etc
eg
@arr=qw(1 3 4 2 4 5);
foreach $number(@arr) {
last if($number == 2);
print "$number";
}
HTH
Regards
Babylakshmi M
_
Get your FREE download of MSN Explorer at http://
> Can someone tell me how I can break out of a foreach loop before the end?
Use the 'last' command. See
http://www.perldoc.com/perl5.6/pod/func/last.html for an explanation of how
to use it. It works for breaking out of any loop e.g. foreach, while,
until.
Best wishes,
Rachel
--
To unsu
for (1..10) {
last if /3/;
print;
}
you'll notice this printing '12'
so 'last' breaks out of the loop if the condition is met
hth
Jos Boumans
- Original Message -
From: "Webmaster" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, August 05, 2001 7:31 PM
Subject: Breaking out