Yep, it sure looks to me like any exceptions raised in the internal eval will go unnoticed. As for the second call to alarm, the authors explain

The second alarm 0 is in case the signal comes in after running the long-running operation, but before getting to the first alarm 0. If you don't do that, you would risk a tiny race condition—but size doesn't matter in race conditions; they either exist or they don't. And we prefer that they don't.
The thing is, if the ALRM signal does arrive at that critical juncture the authors describe, what need is there for alarm 0 anymore? The ALRM already went off! The second alarm 0 would be necessary only if perl automatically reset the alarm interval back to its original value (in this case 5) whenever it received an ALRM signal, but this is not the case, at least not in my OS (Linux).

So I'll go out on a limb here, and have the temerity to correct the venerable TPC by rewriting the recipe's snippet like this:

eval { local $SIG{ALRM} = sub {die "alarm here"}; alarm(5); eval { long_code(); }; alarm(0); die if $@; # propagate error } die if $@ && $@ !~ /alarm here/;
I trust my fellow monks will let me know it if I am wrong.

BTW, in the English edition of TPC, the alarm interval is set for 10 seconds. I guess Russians are more impatient. :-)

the lowliest monk


In reply to Re: second alarm(0) by tlm
in thread second alarm(0) by powerman

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.