On Wed, 6 Dec 2006 21:56:09 +0000, Andy Armstrong wrote: > That pretty much satisfies what I originally asked but doesn't help > in the case where the iterator isn't implemented as a single loop. > I'd really like to have the kind of loop exit communicated back to > the iterator so it can handle it in whatever way is appropriate. For > example the iterator might actually be recursively walking some data > structure without even containing an explicit loop > > sub iter { > my $node = shift; > my $sub = shift; > > iter($node->{left}, $sub) if exists $node->{left}; > $sub->($node); > # Should redo $sub call if redo thrown > # carry on if next thrown > # throw 'last' up the call stack > # if last thrown > iter($node->{right}, $sub) if exists $node->{right}; > } Every block is a loop, so something like this might work (untested): sub iter{ my($node,$sub)=shift; my @args=whatever(); my $continue; eval qq{ $node:{ if(defined \$continue){ # $sub exited via redo } \$continue=0; \$sub->(\@args); }continue{ ++\$continue; } }; if($@){ # $sub exited via die }elsif(!$continue){ # $sub exited via last }else{ # $sub exited normally or via next } } You can get rid of the warning with C, but that has to be in the callback sub, unfortunately. -- Peter Haworth pmh@edison.ioppublishing.com "f y cn rd ths y mst hv bn sng nx"