On Fri, 6 Sep 2002 06:15:22 +0300 , [EMAIL PROTECTED] (Fogle Cpl
Shawn B) wrote:

>I'm writing my first perl script with the llama (the beginner o'riley book)
>but the one thing I need to make a complete program that I don't see in the
>book or the perl faqs (although I'd bet it's there somewhere) is a
>acceptable way to cause the script to terminate. I have been having to goto
>another VC and kill the perl script. It would be nice for me to be able to
>press "Q" but that, to my little bit of knowledge of perl, would require a
><STDIN> that was somewhat passive. Any suggestions? (I won't be asking many
>more newbie questions, as this is the only one that has seemed to stump me
>for the last week two).

Here is something adapted from the Cookbook.
You will need to put everything in a while loop to
periodically check for the keypress.
#################################################
#!/usr/bin/perl
use Term::ReadKey;

$char='q';

while(1){
ReadMode ('cbreak');
if (defined ($ch = ReadKey(-1))){ 
  #input was waiting and it was $ch
     if ($ch eq $char){exit(0);}
}else{
   # no input was waiting
   #your program goes here
   print "############################\n";
   sleep(1);

}
ReadMode ('normal'); # restore normal tty settings
}
###############################################



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to