in reply to I need a different continue

Your foreach won't know how many times to loop until it has already started execution. What you could do is keep a queue of todos and every time you start the loop block, do anything needing to be finished. The last time through your loop the todos generated during the loop won't be executed and will go away.

{ my @todos; foreach my $elt ( ... ) { $_->() for @todos; # Correction for Roy Johnson @todos = (); ... push @todos, sub { print "$elt\n" }; } }

Replies are listed 'Best First'.
Re^2: I need a different continue
by Roy Johnson (Monsignor) on Dec 09, 2004 at 18:26 UTC
    I like this, but you're running all the todos each time through the loop. That is, on iteration N, you'll run N-1 todos. You need to do more like
    { my $todo; foreach my $elt (0..2 ) { $todo->() if $todo; $todo = sub { print "$elt\n" }; } }

    Caution: Contents may have been coded under pressure.