Perl用户输入
发布时间:2020-12-16 06:06:10 所属栏目:大数据 来源:网络整理
导读:如何检测Ctrl D以便在Perl中突破循环? while (1){ $input = STDIN; print $input; #This is where I would check for CTRL+D #last if ($input equals to CTRL+D); EXIT LOOP if($input 0){ print " is positiven"; } elsif($input 0){ print " is negativ
如何检测Ctrl D以便在Perl中突破循环?
while (1){ $input = <STDIN>; print $input; #This is where I would check for CTRL+D #last if ($input equals to CTRL+D); EXIT LOOP if($input > 0){ print " is positiven"; } elsif($input < 0){ print " is negativen"; } else { print " is zeron"; } } 解决方法
使用
while (defined($input = <STDIN>)) { ... } 当用户输入Ctrl-D时,< STDIN>将返回undef. 更一般地说,你可以做到 while (defined($input = <>)) { ... } 并且您的程序将读取@ARGV中指定的任何文件的输入,或者来自< STDIN>如果没有命令行参数. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |