Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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

by RichardK (Priest)
on Aug 10, 2013 at 15:17 UTC ( #1048910=note: print w/ replies, xml ) Need Help??


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


Comment on Re: Checking if an item exists in an array before adding a record to it.
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048910]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2014-08-28 02:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls