in reply to Remove Duplicates Multidimensional Array?
It depends on how you determine whether two entries in the array are "the same." But in general, "removing duplicates" always follows the same principle: put the entries into a hash keyed on the elements that need to be unique, then turn that hash back into an array.
For instance, if two entries having the same manufacturer, model, and year are considered "the same," I would start putting the entries into a hash with the keys being a concatenation of each entry's manufacturer, model, and year. So the first one might become this hash element:
'Kia_Rio_2001' => { 'manufacturer' => 'Kia', 'model' => 'Rio', 'year' => '2001', 'mileage' => '130256', 'color' => 'Metallic Blue' }
Now when you put the second one in the hash, it will get this same key, so one of them will go away. (You'll have to determine in your code whether you want the second one to be ignored or overwrite the first.)
Once this new hash is finished, pull its values into a new array, and the "duplicates" will be gone.
Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.
|
|---|