in reply to Re^2: "next" from within eval {} ?
in thread "next" from within eval {} ?
Thanks for your thoughts.
Actually, your first suggestion was fine, and it looks like a reasonably elegant alternative to using next. Due to short-circuit evaluation, subsequent functions do in fact not execute, once the flag has become false:
sub do_foo { print "running foo"; die "err" if $_==2; $_!=4 } sub do_bar { print "running bar"; "..."; } for (1..5) { print "-----"; my $ok = 1; eval { $ok &&= do_foo(); $ok &&= do_bar(); }; if ($@) { warn $@; next; } next unless $ok; print; } __END__ ----- running foo running bar 1 ----- running foo err at ./test.pl line 5. ----- running foo running bar 3 ----- running foo ----- running foo running bar 5
Still, I'm not sure what's wrong with using next from within eval. I mean, you don't generate warnings without a good reason...
|
|---|