in reply to simple timeout
Like I said before, PodMaster demonstrated that 5.8.4 has an alarm function, but it doesn't appear (to me?) capable of interupting IO, which is somewhat limiting in application.
As I also said, there are (usually) other ways of interupting things that take a long time. The problem is that what will work for one thing will not necessarially work for another, so you need to be specific about what it is your doing instead of keep posting the same hypothetical question.
For example, the psuedo problem you've posed could be tackled this way:
#! perl -slw use strict; use Term::ReadKey; $| = 1; sub ReadLine { my $timeout = shift; my $start = time; ReadMode 1; my $buf; while( time < $start + $timeout ) { if( my $c = ReadKey 0.5 ) { printf $c; $buf .= $c; ReadMode( 0 ), return $buf if ord( $c ) == 13; } } ReadMode 0; return undef; } for my $n ( 1 .. 10 ) { if( my $buf = ReadLine( 10 ) ) { print "$n Got $buf"; } else { print "$n timed out"; } } __END__ [16:35:02.57] P:\test>alarmed.pl Subroutine ReadLine redefined at P:\test\alarmed.pl line 7. 1 Got fred 2 Got bill 3 Got John 4 timed out 5 timed out 6 timed out 7 Got blech 8 Got one 9 Got two three 10 Got four
But that almost certainly won't solve your problem. I also previously referred you to this thread Timeouts/timers on Win32 system, which contains a couple of other possible solutions. One using threads and one using Win32::Process.
Which, if any of these solutions might work for your particular problem depends very much on what your real problem is, but keep asking "Why doesn't alarm work", won't make it work.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: simple timeout
by disciple01 (Novice) on Nov 08, 2004 at 17:10 UTC | |
by BrowserUk (Patriarch) on Nov 08, 2004 at 18:56 UTC | |
by dwilson@d7net (Initiate) on Nov 08, 2004 at 17:59 UTC |