in reply to how to set alarm in perl

See alarm.

$SIG{ALRM} = sub { warn "3 days over!\n"; exit }; alarm(86400 * 3);

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^2: how to set alarm in perl
by Anonymous Monk on Sep 11, 2006 at 07:44 UTC
    now i m confused
    the above code will kill tests after there days. and it prints messages " 3 days over" and exits
    i can also write a code to print final report inside the sub function
    if test get over before 3 days then where should i place code to finally create a report.
    i mean where to place code to check if test over before 3. should it come after above code or before above code.
      $SIG{ALRM} = sub { report(); exit }; alarm(86400 * 3); # your test code here ... # at the end, print report report(); sub report { # your reporting code }

      At the end of your test script you invoke report(). If the script happens to run for three days, the alarm handler will invoke report() and terminate the script.

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}