Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

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

by davido (Cardinal)
on Dec 02, 2005 at 06:54 UTC ( [id://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.


Dave

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-25 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found