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

Hi all,

I want to prompt user to enter a string and if not entered in a time period (say 20 seconds) print "Time expired".
How to do this ??
Thanks in advance!!!!

Replies are listed 'Best First'.
Re: Keyboard timeout in perl
by Corion (Patriarch) on Mar 13, 2010 at 08:22 UTC
Re: Keyboard timeout in perl
by Khen1950fx (Canon) on Mar 13, 2010 at 11:40 UTC
    I used Time::Out for the following example. It'll prompt for a command, but don't enter one. It'll come back with "Operation timed-out". If you enter a command, it'll return "Done".
    #!/usr/bin/perl use strict; no warnings 'redefine'; use ExtUtils::MakeMaker qw(prompt); use Time::Out qw(timeout); use Time::HiRes qw(alarm); test("Done\n"); if ($@) { print "Operation timed-out\n"; } sub test { timeout 20.37, @_ => sub { prompt("Please enter command: "); print "$_[0]\n"; }; }
Re: Keyboard timeout in perl
by ungalnanban (Pilgrim) on Mar 13, 2010 at 10:40 UTC

    using IO::Select module we can check the file
    handler is ready or not for reading data.

    Refer the following link
    IO::Select

    --$ugum@r--