Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 在Perl中等待输入的定义时间段_Linux_Perl - Fatal编程技术网

Linux 在Perl中等待输入的定义时间段

Linux 在Perl中等待输入的定义时间段,linux,perl,Linux,Perl,怎么说 等待10秒,等待输入 如果未识别输入 打印一些东西 在Perl中,您可以使用 使用严格; 使用警告; 子超时{ 我的($f,$sec)=@; 返回评估{ 本地$SIG{ALRM}=sub{die}; 警报(秒); $f->(); 报警(0); 1. }; } 我的$text; my$ok=超时(sub{$text=;},10); 如果($ok){ 打印“输入:$text”; } 否则{ 打印“发生超时\n”; } 和可以在超时的情况下读取 #!/usr/bin/env perl use

怎么说

等待10秒,等待输入
如果未识别输入
打印一些东西

在Perl中,您可以使用

使用严格;
使用警告;
子超时{
我的($f,$sec)=@;
返回评估{
本地$SIG{ALRM}=sub{die};
警报(秒);
$f->();
报警(0);
1.
};
}
我的$text;
my$ok=超时(sub{$text=;},10);
如果($ok){
打印“输入:$text”;
}
否则{
打印“发生超时\n”;
}
可以在超时的情况下读取

#!/usr/bin/env perl

use strict;
use warnings;
use IO::Select;

my $select = IO::Select->new();
$select->add( \*STDIN );

my $input = "NONE";
if ( $select->can_read(10) ) {
    $input = <STDIN>;
}

print "Got input of $input\n";
#/usr/bin/env perl
严格使用;
使用警告;
使用IO::Select;
我的$select=IO::select->new();
$select->add(\*STDIN);
我的$input=“无”;
如果($select->can_read(10)){
$input=;
}
打印“已获得$input的输入\n”;

也许可以使用:Perl Cookbook描述了一个涉及和的解决方案。这可能会对您有所帮助。
#!/usr/bin/env perl

use strict;
use warnings;
use IO::Select;

my $select = IO::Select->new();
$select->add( \*STDIN );

my $input = "NONE";
if ( $select->can_read(10) ) {
    $input = <STDIN>;
}

print "Got input of $input\n";