perl如何得到多个数组中第3个数字比较的最小值
发布网友
发布时间:2022-12-10 03:07
我来回答
共3个回答
热心网友
时间:2024-11-24 13:06
#!/usr/bin/perl -w
use strict;
use warnings;
my %min;
while (<DATA>) {
my ($k, $v)=/\s(\d+(?:\.\d+)?)\s+(\d+(?:\.\d+)?)\b/;
push @{$min{$k}}, $v;
}
for (sort {$a<=>$b} keys %min) {
print $_, "\t",
shift @{[sort { $a<=>$b } @{$min{$_}}]}, "\n";
}
__DATA__
#L 16.5435275 18.814415 16.5435275 19.61426 r150.12 P 41
#L 16.5435275 19.61426 16.9433225 19.61426 r150.12 P 41
#L 16.9433225 19.61426 17.0766725 19.48091 r150.12 P 41
#L 16.9433225 19 17.0766725 19.48091 r150.12 P 41
#L 17.0766725 19.48091 17.0766725 19.214465 r150.12 P 41
热心网友
时间:2024-11-24 13:06
假设你的数据存在file.txt里面
#!/usr/bin/perl
use strict;
use warnings;
open(FH, "file.txt")||die $!;
$_ = <FH> || die $!;
my @arr = split(/\s+/);
my ($minA, $minB) = @arr[3,4];
while(<FH>){
my @arr = split(/\s+/);
if($arr[3] < $minA){ ($minA,$minB)=@arr[3, 4];
}
}
print "$minA $minB\n";
热心网友
时间:2024-11-24 13:07
while(<FILE>){
if(/#L \d+\.\d+ (\d+\.\d+)/){push @m,$1;}
}
@n=sort {$m[$a]<=>$m[$b]}0..$#m;
print $n[0];