Enter a string:
たとえば、、、の後にa
2b
回入力c
すると、停止せず、キーで停止できない無限ループが発生しCtrlますか?DReadKey
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";
}