Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

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

by RichardK (Parson)
on Aug 10, 2013 at 15:17 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1048910]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2024-04-19 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found