- 论坛徽章:
- 0
|
问题已解决了。代码分享给那些需要的人吧~
open (IN,"< test.txt") || die "Can't open \n";
my %hash=();
my @arrays = <IN>;
my @lie = sort {(split /\s+/,$a)[2] <=> (split /\s+/,$b)[2] }@arrays;
for (my $i=0;$i<=$#lie;$i++) {
my @line=split(/\s+/,$lie[$i]);
my($name,$direction,$start,$end)=("$line[0]","$line[1]","$line[2]","$line[3]");
if (defined($hash{$name}{$direction})) {
my @tmp=(@{$hash{$name}{$direction}},$start,$end);
$hash{$name}{$direction}=\@tmp;
}else{
$hash{$name}{$direction}=[$start,$end];
}
}
foreach my $n (sort keys %hash) {
foreach my $d (sort keys %{$hash{$n}} ) {
print "$n $d @{$hash{$n}{$d}}\n";
}
}
close (IN);
经过试验,没有问题的。 |
|