in reply to loop labels and script dying
If you need to exit on a specific condition, use last:my @numbers = (1..6); foreach my $number (@numbers) { print $number; }
If you want to continue based on a subroutine, you probably don't need to eval it, just call it, unless you'll be using it to do primitive error handling.my @numbers = (1..6); foreach my $number (@numbers) { last if $number == 4; print $number; }
my @numbers = (1..6); foreach my $number (@numbers) { next if next_loop($number); print $number; } sub next_loop { # return some true or false value my $num = shift; return ($num % 2); # will skip over odd numbers }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: loop labels and script dying
by dragonchild (Archbishop) on Sep 03, 2003 at 13:14 UTC |