in reply to Exiting eval via next: is that so bad?
Well, you should be aware of the fact that the next from within the eval jumps to the end of an enclosing loop, which might be a little bit surprising. Example:
The block after eval does not count as a loop block (same as do), so the loop commands next, redo and last work on the outer block. To make the eval block a loop block (so that you can redo it e.g.) double the braces like this:my $var = 5; { eval {$var = 3; next}; $var = 4; } print $var; # 3 !!
eval {{ $i++; redo unless do_sth($i); }}
-- Hofmator
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Exiting eval via next: is that so bad?
by dd-b (Monk) on Sep 23, 2011 at 19:36 UTC | |
by Anonymous Monk on Sep 24, 2011 at 02:01 UTC | |
by dd-b (Monk) on Oct 17, 2011 at 20:48 UTC | |
by Anonymous Monk on Oct 18, 2011 at 11:00 UTC | |
by jdporter (Paladin) on May 05, 2012 at 01:25 UTC | |
by Anonymous Monk on May 05, 2012 at 08:10 UTC |
In Section
Seekers of Perl Wisdom