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


in reply to To Hash or to Array--Uniqueness is the question.

Hash inserts are O(1) (or close to), while uniquely inserting into an array is O(N) (unless you insert everything and remove dups later).

The only reason you'd want something other than a hash is if you wanted something other than the string representation to be unique. And even then, it would be best if you could derive a unique string from the object and still use a hash.

For example, case-insensitive uniqueness:

$hash{lc($_)} = $_;

For example, unique object id:

$hash{$obj->{id}} = $obj;