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

hi monks, i want to create a script the user has to input some value on the command line and exit the script after a time limit. i don't want to use SIG ALRM. is there any easy ways? "Or the user has to enter input within a certain time limit, or the script ends?" Hello, again, i mean enter the value within a certain time limit.

Replies are listed 'Best First'.
Re: help with time limit script
by scmason (Monk) on May 19, 2005 at 16:45 UTC
    To elaborate on what was just said:

    You are going to need to have one process/thread timing and the other waiting for user input.

    One process/thread should sleep, then check if the user input has happened on the other thread/process. Sleep, then check. Sleep, then check. If input does not happen within a certain time, the timing process should kill the one waiting for user input (and then commit suicide)

    "Never take yourself too seriously, because everyone knows that fat birds dont fly" -FLC
Re: help with time limit script
by mrborisguy (Hermit) on May 19, 2005 at 15:28 UTC

    Do you mean the user inputs the value, then the script exits after a time limit? Or the user has to enter input within a certain time limit, or the script ends?

    If it's the first one, look into the sleep function. (sleep n - sleep for n seconds)

    -Bryan

Re: help with time limit script
by rev_1318 (Chaplain) on May 19, 2005 at 19:05 UTC
    Have a look at Term::ReadKey. The ReadKey function has a timeout option...

    Paul