Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

remove duplicates from a two (or more) field list

Status
Not open for further replies.

MrCBofBCinTX

Technical User
Dec 24, 2003
164
0
0
US
I am searching for different items of interest to then get full details later.
I want to look at details for each individual item, but my search produces two useful fields, both of which have duplicates, but (usually) a combination of the two fields produces a unique item.

field1 = 97865 field2 = DF-54H
field1 = 97865 field2 = DF-53K
field1 = 97865 field2 = DF-54HFG
field1 = 97865 field2 = DF-57H
field1 = 97855 field2 = DF-54H
field1 = 90003 field2 = DF-54H
field1 = 23407 field2 = DF-54H
field1 = 97456 field2 = DF-54H

I know how to remove duplicates from an array, but how can I do this other than joining the two fields with a separator character?
Code:
push @list,join(":",$field1,$field2);
@list = grep ++$temp{$_} < 2, @list;
then splitting.

Is there a better method or is this good enough?
 
MrCBofBCinTX said:
Is there a better method or is this good enough?
Does it work for you? Then it's good enough. :)

If order isn't important you could use a hash of hashes to make the deduping easier.
 
Seems to be working ok. I need to go find one of those good sets of duplicates to make sure. Of course, doing this brought to notice a small previous error in one of my modules for this matching.
So easy to skip a character and so easy to miss the bug!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top