Subject: | unexpected behaviour mixing ReadKey(-1) and ReadKey(0) |
The following program
A) Works if you type any key faster than 2 seconds after running it
B) Fails if you wait 3 seconds or more (ends after returing undef from
the "blocking" read even though I type nothing!)
I'm using RedHat ES3.5 Linux (2.4.21-32.0.1.ELsmp) and connecting as
root via SSH.
Interestingly: the exact same program on Fedora Core 4 (2.6.11-
1.1369_FC4smp), as the same user (root), with an identical bash "env"
works fine.
#!perl
use Term::ReadKey(2.30);
# :-( not exported... print "Using Term::ReadKey Versions
$Term::ReadKey::VERSION\n";
ReadMode 3; # cbreak mode
local $|=1; # make STDOUT go out immediately.
print "Yeah?";
sleep 2; # Give us time to shove some keys into the
buffer
$key=ReadKey(-1); # Flush one char
$buf=ReadKey(0); # Blocking read
print " I flushed '$key' and got '$buf'\n";
ReadMode 0; # Reset