in reply to Re: default value after timeout
in thread default value after timeout
I am new to Perl, but I would have thought this had come up more. I am still interested in other solutions, so keep them coming!#!/usr/bin/perl -w use strict; my $value; my $timedout; sub timedout { $value = "default"; $timedout = 1; die; } eval { local $SIG{ALRM} = 'timedout'; alarm 10; print "Please enter the value - you have 10 seconds\n"; chomp ($value = <STDIN>); alarm 0; }; alarm 0; if ( $timedout ) { print "You timed out - setting value to $value\n"; } else { print "You entered $value within the 10 second time frame\n"; }
|
|---|