- 论坛徽章:
- 32
|
回复 8# li0924
噢,是的,这都被你发现了,待会再改,先用perl来一发~ - #!/usr/bin/perl
- open(FILE1, 'a') or die;
- open(FILE2, 'b') or die;
- my(%hash1, %hash2);
- while(<FILE1>){
- @_ = split;
- push(@{$hash1{$_[1]}}, $_[0]);
- push(@{$hash2{$_[1]}}, $_[2]);
- }
- while(<FILE2>){
- @_ = split;
- lable:
- my $temp = shift @{$hash2{$_[0]}};
- next unless defined $temp;
- if($temp > $_[2]){
- $temp -= $_[2];
- unshift(@{$hash2{$_[0]}}, $temp);
- }else{
- print join("\t", $hash1{$_[0]}[0], @_[0,-2], $temp), $/;
- $_[2] -= $temp;
- shift @{$hash1{$_[0]}};
- next unless $_[2];
- goto lable;
- }
- print join("\t", $hash1{$_[0]}[0], @_), $/;
- }
- close(FILE1);
- close(FILE2);
复制代码 |
|