Oh yes, you can. But you will not only leave the eval but the loop around it, too. If there is no loop around that eval, you'll die—just like your code demonstrated.

No. You don't leave the eval, you just evaluate a last that will make you leave the loop.

even if the code in my previous post had died in the eval{}, the loop would have continued and the output would have been 123

Of course, but it will not die in the eval, because eval { last; } is like saying last; -- i.e: you're just evaluating the code

eval { bleh(); } is really like saying just bleh(); so your code is simply:

for (1) { last; }

Otherwise, if it already exits the eval block, why does it exit the loop too?

so just like saying last; outside a loop will die, saying it inside an eval that is outside a loop will die too. It will exit the eval, but just because it died, not because it skipped the block.

--
Leviathan.

In reply to Re^4: Ways to control a map() operation by Leviathan
in thread Ways to control a map() operation by Booger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.