我试图摆脱某种标志的stdin,但是当我运行我的代码时,我仍然必须使用控件d来突破。可能有人请点击这里给我一个指针感谢:突破的最佳方式<STDIN>
while(my $line = <STDIN>){
chomp $line;
last if $line == 0;
push @stdin, $line;
}
我试图摆脱某种标志的stdin,但是当我运行我的代码时,我仍然必须使用控件d来突破。可能有人请点击这里给我一个指针感谢:突破的最佳方式<STDIN>
while(my $line = <STDIN>){
chomp $line;
last if $line == 0;
push @stdin, $line;
}
被更新(两次)
我会去使用比较一种或另一种的字符串。 ==
是一个数字比较,并将比较的两侧强制为数字。几乎比纯数以外的任何串卷起等于0
while (my $line = <STDIN>) {
chomp $line;
# use the string comparison operator...
last if $line eq "0";
# or use a match operator...
# last if $line =~ m/^0$/;
# or match on some special number
# last if $line == 3.1415926;
push @stdin, $line;
}
我在窗口测试此:
perl -e "while(my $line = <STDIN>){chomp $line;last if $line =~ m'^[.]$'}END{print @l}"
和UNIX:
perl -e 'while(my $line = <STDIN>){chomp $line;last if $line=~m/^[.]$/;[email protected],$line}END{[email protected],$/}'
OLD ANSWER
Ctrl + Z in Windows?已经内置的标志。在Unix上,您可以使用Ctrl + D。
你是否输入0?这是在Windows或Unix下? – chepner 2012-08-08 18:20:03
适用于Windows的v5.14.2。 – 2012-08-08 18:29:52
关于此的最后说明。将脚本更改为'last if line $ 1',看看会发生什么。我认为perl中0的“魔术”在这里咬你。 – Mark 2012-08-08 21:13:33