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


in reply to Checking if an item exists in an array before adding a record to it.

Turning your array into a hash is going to visit each member of the array and have to do all the memory management for the hash so my guess is that it will be slower than grep. But benchmark it if you really want to know.

You could use first from List::Util so something like :-

push @array,$value unless first {$_ eq $value} @array;

Or push all your values to the array and then get just the unique values using uniq from List::MoreUtils