Enter a string:
例如a
,当我键入, b
,c
然后两次Ctrl+D我得到一个无限循环,它不会停止ReadKey
并且我不能用Q键停止?
#!/usr/bin/env perl
use warnings;
use 5.10.1;
use Term::ReadKey;
while( 1 ) {
my $c;
say "Press the \"q\" key to quit.";
print "Press the \"e\" key to enter a string: ";
{
$|++;
Term::ReadKey::ReadMode 'ultra-raw';
$c = ReadKey 0;
Term::ReadKey::ReadMode 'restore';
}
exit if ord( $c ) == 3; # Control C
last if $c eq 'q';
if ( $c eq 'e' ) {
print "\nEnter a string: ";
my $string = <>;
if ( not defined $string ) {
say "Undefined";
}
else {
chomp $string;
say "You entered |$string|";
}
}
say "Still running";
}