in reply to Re^2: Alarms with ActivePerl do not work properly (small modification)
in thread Alarms with ActivePerl do not work properly

The downside to your modification is that if lines come 3 per second, you still only read one per second. And if lines come one every 2 seconds, your alarm has even odds of not doing anything.

The sleep can be varied to suit. It would be better to invoke the sleep before the read.

In essence, the trick is to ensure that the read doesn't block. I've posted several other variations on the theme here over the years. Some more thorough than others.

I also think that the emulation can be fixed. Just use a select/sysread loop, ...

select doesn't work on filehandles on Win32.

In fact it is even possible to make that fix in pure Perl.

I guess that "fact" is tempered by the above.

  • Comment on Re^3: Alarms with ActivePerl do not work properly (small modification)

Replies are listed 'Best First'.
Re^4: Alarms with ActivePerl do not work properly (small modification)
by tilly (Archbishop) on Jan 13, 2011 at 06:33 UTC
    Windows is really that broken?

    I'm glad I don't use Windows then.

      Windows is really that broken?

      Not broken just different. Ie. not POSIX. It is Perl's attempt to make the world look like POSIX that is broken.

      I'm glad I don't use Windows then.

      Kinda begs the question re: your involvement in this thread.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      Basically, the proper approach on Windows would be either to use (OS) threads, one per handle on which to perform IO, or to use asynchronous IO with either callbacks or locks. The whole thing is not entirely unlike other mechanisms, but the mechanism used by Perl to implement select on Windows, namely, the select function of Winsock.dll, only supports (its own) sockets and not the various other handles that can be signalled on Windows.