Re: skip/delete lines with dup keys
- From: Chris <ithinkiam@xxxxxxxxx>
- Date: Wed, 27 Jul 2005 10:15:15 +0100
Jeff 'japhy' Pinyan wrote:
On Jul 26, Jim said:
Looking for ideas on the best way to skip/delete a line if the LOAN_NO repeat even if other fields ion in the record are not the same (need to remove lines with dup key fields). The code below seems to work, but there must be a better way.
Your code works fine, assuming the duplicates are right after one another.
If not or if you want to avoid sorting then you need to use a hash:
use warnings; use strict;
# other file opening stuff
my %hash;
while (<F>) {
chomp;
my ($id,$score,$bal) = split (/,/, $_);
next if exists($hash{$id});
print OUT;
$hash{$id}++;
}
.- References:
- Re: skip/delete lines with dup keys
- From: Jeff 'japhy' Pinyan
- Re: skip/delete lines with dup keys
- Prev by Date: Re: 'Use Lib' problem...
- Next by Date: Messenger
- Previous by thread: Re: skip/delete lines with dup keys
- Next by thread: Redirect to referring page?
- Index(es):