Perl用户输入

Perl用户输入,perl,input,Perl,Input,如何检测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 positive\n"; } elsif($input <

如何检测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 positive\n";
   }

   elsif($input < 0){
    print " is negative\n";
   }

   else { print " is zero\n"; }
}
while(1){
$input=;
打印$input;
#这是我检查CTRL+D的地方
#最后一个if($input等于CTRL+D);退出循环
如果($input>0){
打印“为正\n”;
}
elsif($input<0){
打印“是负片\n”;
}
否则{print“为零\n”;}
}
使用

并且您的程序将从
@ARGV
中命名的任何文件中读取输入,如果没有命令行参数,则从
中读取输入

while (defined($input = <STDIN>)) {
    ...
}
while (defined($input = <>)) {
    ...
}