當我Enter a string:
例如a
,b
,c
後類型,然後兩次按Ctrl +d我得到一個無限循環不上ReadKey
叫停而我不能停止與Q關鍵?期限:: ReadKey, 「STRG + d」 和STDIN
#!/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";
}
我怎麼能抓住'Ctrl'-'D'? –