打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用Perl代码实现像DOS中“请按任意键继续”效果
 

用代码实现像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();  

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
会荡的女人
Excel VBA 8.5获取唯一值,听说你喜欢用字典
DevExpress控件在winform上的一些控件的常用属性设置
POSIX 线程详解
WinForm控件开发总结(十二)
键盘对元素的操作
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服