[英]perl subroutine from reading STDIN (“Press enter to reset”) only works the first time
I have made a little perl program for a kids demonstration and I'm trying to keep the screen clean and simple with a clear
subroutine, but it's only working the first time, and then will not respond to input, only clearing the screen, and I can't work out why. 我为儿童演示制作了一个小小的perl程序,我试图通过一个
clear
子例程来保持屏幕的清洁和简单,但是它只是第一次工作,因此不会响应输入,只会清除屏幕,并且我不知道为什么。 I'm also sure that there's a simpler way to do this in general, so maybe the whole thing should be scrapped. 我也确信一般来说,有一种更简单的方法可以做到这一点,所以也许应该废弃整个事情。
There is a prompt for a query from STDIN, then once it's checked the database it calls the restart
sub. 会提示您从STDIN进行查询,然后一旦检查数据库,它将调用
restart
子程序。
What I have: 我有的:
while (my $seq = <STDIN>){
chomp($seq);
if (exists $references{$seq}){
... blah blah blah
sleep(2);
&restart;
}else{
print "\nOops! This doesn't exist!\n";
sleep(2);
&restart;
}
}
sub restart {
print "\nPress Enter to restart\n";
while (my $in = <STDIN>){
if($in eq "\n"){
system("clear");
print $prompt;
}
}
}
Thanks for looking! 感谢您的光临!
In sub restart
you are looping on <STDIN>
again. 在
sub restart
您将再次在<STDIN>
上循环。 This will continue to loop, without returning to the main loop, until STDIN receives an EOF. 这将继续循环,而不返回主循环,直到STDIN收到EOF。 You could put a
return
after print $prompt;
您可以在
print $prompt;
之后放一个return
print $prompt;
to return to the main loop. 返回主循环。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.