[sf-perl] Sorting vs. hash

Neil Heller nheller at silcon.com
Fri Mar 28 12:44:28 PDT 2008


An interesting question came up.

Suppose you have a large number (> 250k) of strings in an array.
You wish to eliminate duplicates.

Is it faster to sort the array and then iterate once through the list
(writing selected ones to a new array) or write them all into a hash (at
which time duplicates would be naturally eliminated)?

Neil Heller




More information about the SanFrancisco-pm mailing list