用代码实现像DOS中“请按任意键继续”效果
1. 按回车键继续:
# Do something
<STDIN>; # waiting for any key
# Do something else
2.按任意键继续:
use Term::ReadKey;
$| = 1;
print "Press any key to continue...";
ReadMode 4; # Turn off controls keys
while (! defined ReadKey(-1)) {}
ReadMode 0; # Reset tty mode
$| = 0;
效果和windows上system('pause');一样
与用户交互以退出循环,如:按任意键终止循环
是要用多线程实现。
use threads;
use threads::shared;
my $control:shared = 0;
sub EndIt
{
my $con=shift;
<>;
$$con=1;
return;
}
my $thd=threads->create("EndIt",\$control);
foreach (@data){
...................
if ($control==1){
print STDERR "User cancels....\n";
last;
}
...................
}
$thd->join();
联系客服