http://www.perlmonks.org?node_id=1020089


in reply to CountDownTimer for my perl program,

tmharish ++

Here is the exact code to timeout for 25 minutes.

use strict; use warnings; use utf8; eval { local %SIG; $SIG{ALRM}= sub{ die "timeout reached, after 25 minutes!\n"; }; alarm 25*60; # 25 minutes. while(1) { sleep(1); print "Hello Perl\n"; } alarm 0; }; alarm 0; if($@) { print "Error: $@\n"; } exit(0);

Replies are listed 'Best First'.
Re^2: CountDownTimer for my perl program,
by MidLifeXis (Monsignor) on Feb 22, 2013 at 13:52 UTC

    See the warning about using sleep and alarm being used in tandem.

    --MidLifeXis

Re^2: CountDownTimer for my perl program,
by vinoth.ree (Monsignor) on Feb 25, 2013 at 04:46 UTC