Chris Wagner wrote:
> U want to set an alarm() so the program can signal itself after 10 secods.
> I'll just quote O'Reilly:
Except he's on Win32 - have you tried that code ?
I'd use Win32::Console PeekInput calls with a Time::HiRes::usleep after
each poll and time the total time limit with Time::HiRes::gettimeofday.
use Time::HiRes qw (usleep gettimeofday);
use Win32::Console;
my $CONSOLE = new Win32::Console(STD_INPUT_HANDLE);
$CONSOLE->Mode(ENABLE_PROCESSED_INPUT);
my $start = gettimeofday;
while (1) {
my @event = $CONSOLE->PeekInput();
# check @event for keyboard event here
if (defined $input[0] and $input[0] == 1) {
# process kybd event
}
usleep 1000000;
last if gettimeofday - $start > 10;
}
> $SIG{ALRM} = \&timed_out;
> eval {
> alarm (10);
> $buf = <>;
> alarm(0); # Cancel the pending alarm if user responds.
> };
> if ($@ =~ /GOT TIRED OF WAITING/) {
> print "Timed out. Proceeding with default\n";
> #....
> }
>
> sub timed_out {
> die "GOT TIRED OF WAITING";
> }
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs