in reply to loop labels and script dying

Why are you using the next inside the foreach loop, when the foreach loop itself will iterate over the list of numbers?
my @numbers = (1..6); foreach my $number (@numbers) { print $number; }
If you need to exit on a specific condition, use last:
my @numbers = (1..6); foreach my $number (@numbers) { last if $number == 4; 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) { 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
    I'm going to guess it's something like:
    foreach my $foo (@foos) { # Do common processing next if is_done_processing(foo); # Do more processing next if is_done_now?(foo); # Do still more processing next if can_we_go_now??(foo); # Do cruel and unusual processing last if is_dead(foo) or is_suing_programmer(foo); }

    ------
    We are the carpenters and bricklayers of the Information Age.

    The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6

    Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.