in reply to How to use alarm?

The documentation for alarm hints at requiring a newline:
local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required

But, it does not offer an explanation :(

Replies are listed 'Best First'.
Re^2: How to use alarm?
by broomduster (Priest) on Jul 25, 2008 at 23:03 UTC
    It's because that example is using die (vs. print) and the way die needs \n to avoid printing $! (which will affect the comparison against that die message later in that example).

    The OPs problem is just buffering. Either

    $| = 1; $SIG{ALRM} = sub {print "checking"};
    or
    $SIG{ALRM} = sub {print "checking\n"};
    fixes his problem.

      A last argument to die ending in something other than \n prints the file and line where the die was called, not $!.</pedant>

      The cake is a lie.
      The cake is a lie.
      The cake is a lie.

        <pedant>You forgot to open your pedant tag.</pedant>
        I wouldn't call that pedantry: thinking the die message includes the value of $! by default is a serious misunderstanding of die, in disagreement of the "best practice" to include $! in the error message yourself.
        <mea_culpa> Indeed. Shoulda re-read the doc before punching 'create'. </mea_culpa>

        Long week.