in reply to Re: Ways to control a map() operation
in thread Ways to control a map() operation
You really cannot leave eval{} with a last.
last will exit a loop block, and eval {} is not a loop block. Your example works here because you're cheating :) you placed a loop block around the eval, which is what last is exiting, and not the eval itself.
Compare your version with
eval { print "1\n"; last; print "2\n"; };
Seems to work you say? Take a closer look.
eval { print "1\n"; last; print "2\n"; }; print "Oops: $@\n" if $@;
Aha!!! the only reason we exit from the eval is because we are dying, and not because last allows you to exit eval. You may argue that it's exiting in either way, but that's not a good solution since you lose the advantages of eval that way.
--
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Ways to control a map() operation
by betterworld (Curate) on Jul 16, 2006 at 11:13 UTC | |
by Leviathan (Scribe) on Jul 16, 2006 at 11:41 UTC | |
by betterworld (Curate) on Jul 16, 2006 at 11:56 UTC | |
by Leviathan (Scribe) on Jul 16, 2006 at 12:19 UTC | |
by betterworld (Curate) on Jul 16, 2006 at 14:57 UTC | |
|