Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: To Hash or to Array--Uniqueness is the question.

by davido (Archbishop)
on Dec 02, 2005 at 06:54 UTC ( #513526=note: print w/replies, xml ) Need Help??

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

Using a hash for uniqueness is the canonical means of maintaining a unique set with Perl. However, the 'values' needn't be "arbitrary". There are all sorts of uses for the values, such as:

  • A count of how many times a particular entry has been seen.
  • An anonymous arrayref (or in other words, a HoA - hash of arrays), where the array pertaining to each hash entry contains a list of positions at which a particular entry was found.
  • A priority for a given entry (priority, sort order, timestamp, or whatever other info might be interesting).

Your second option, "Use an array; filtering it through a routine that makes it unique" is probably going to still employ a hash as the means of filtering. The array simply would keep the entries in some specific order. But as mentioned above, you can keep track of order by simply using the filter hash's values.


  • Comment on Re: To Hash or to Array--Uniqueness is the question.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://513526]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2017-08-22 12:26 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (335 votes). Check out past polls.