Loan Tran wrote:
I would like to know if there is any way to process a
file using perl to get rid of extra records based on a
key value.
My key is the 1st field and in my output file I only
want 1 record per key and it has to be the last record
in the file.
So for example here is my file:
1 5 4
1 0 2
1 2 2
2 0 2
3 0 3
3 4 6
And here is the output file I want:
1 2 2
2 0 2
3 4 6
As usual, use a hash:
my %hash;
while (<FILE>) {
my ($k, $v) = split ' ', $_, 2;
$hash{$k} = $v;
}
print "$_ $hash{$_}" for sort keys %hash;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>