in reply to How do I loop until keyboard input?

It is not so easy to do this directly from STDIN, you might be better off using Term::ReadKey:

use Term::ReadKey; my $done = 0; my $choice; ReadMode 4; while ( !$done ) { if ( defined( $key = ReadKey(-1) ) ) { $choice = uc ( $key); $done = 1 if $choice eq 'Q'; } } + ReadMode 0;

/J\

Replies are listed 'Best First'.
Re^2: How do I loop until keyboard input?
by skitchy (Initiate) on Dec 15, 2004 at 15:25 UTC
    I have tried Readkey but from my experience it is still waiting for input before it continues the loop.
    #!/usr/bin/perl -w use strict; use Term::ReadKey; my $done = 0; my $choice; my $key; ReadMode 4; while (! $done) { if (defined($key = ReadKey(-1))) { print "Test\n"; $choice = uc ($key); $done = 1 if ( $choice eq "Q" ) } } ReadMode 0;

      No it isn't if you have ReadMode 4 set. Of course if you have actually tried the code and it doesn't do what you expect then please can you send me a bug report stating the OS, Term::ReadKey and Perl version and with the exact code that you were trying to use.

      /J\

        retard error had the print statement in the wrong loop. I need more coffee!!