我不确定为什么这种 Perl 排序不起作用。请建议如何解决这个问题。
while (<>) {
chomp;
if (/VIOLATE/) {
@lines = split " ", $_;
#print "$lines[-2]\n"; ## Print last but one column
my @viol = "$lines[-2]\n";
@sorted = sort {$a <=> $b} @viol;
print "@sorted";
}
};
命令 :perl test.pl test.log
测试日志:
0.98 2.04 -1.106 VIOLATE
0.98 2.04 3.06
0.98 2.04 -11.06 VIOLATE
0.98 2.04 -1.06 VIOLATE
0.98 2.04 1.06
0.98 2.04 -0.226 VIOLATE
0.98 2.04 -2.06 VIOLATE