in reply to Avoiding goto
duff has a nice clean solution. If you need something more resilient (i.e. cleanup even if the code dies), you can use the following:
use Sub::ScopeFinalizer qw( scope_finalizer ); for my $a (@b) { my $anchor = scope_finalizer { perform_cleanup(); }; next if ...; do_something(); next if ...; do_something_else(); next if ...; do_something_again(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Avoiding goto
by elTriberium (Friar) on Jun 11, 2010 at 00:24 UTC |