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" }; } }
In reply to Re: I need a different continue
by diotalevi
in thread I need a different continue
by DrWhy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |