Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear All

I want to register a callback subroutine for particular timeout to come out of the wile loop. Could anyone provide some idea to do it?

Thanks..

Replies are listed 'Best First'.
Re: Callbacks for Timeouts
by Anonymous Monk on Oct 28, 2009 at 06:18 UTC
    Register? perldoc -f alarm
    eval { local $SIG{ALRM} = sub { die "alarm\n" }; # NB: \n required alarm $timeout; $nread = sysread SOCKET, $buffer, $size; alarm 0; }; if ($@) { die unless $@ eq "alarm\n"; # propagate unexpected errors # timed out } else { # didn't }
      Dear Monk, Thanks, but I don't want to use SIGALARM. Is there any other way?
        I don't think so
Re: Callbacks for Timeouts
by zentara (Cardinal) on Oct 28, 2009 at 14:57 UTC
    I don't want to use SIGALARM. Is there any other way?

    If you don't want to use alarm, then the the general solution used for this type of timer interrupt is called an "event loop" system. Gui's like Tk, Wx, Gtk2, and non -gui's like Poe, and Glib are your best solutions..... see Roll your own Event-loop for example.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku