http://www.perlmonks.org?node_id=910924


in reply to Perl sorting unique values

When you want to find the unique entries in (especially) a large collection of items, first you sort it, then you walk through the list to fetch the unique items.   (Thanks to the sort, all duplicate items are adjacent.)   You cannot, AFAIK, do this in just one step, unless the sort-utility or package that you are using provides that option.

TMTOWTDI, of course.   Memory-based tricks such as hash-tables are certainly fine up to a point.   The sort-then-uniq strategy will handle data of any quantity and will do so with linear performance.

Existing CPAN packages, as mentioned, are always to be looked-for first.   (No matter what you’re doing, it has been done before.)