Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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.


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
Node Status?
node history
Node Type: note [id://513526]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (11)
As of 2014-12-19 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (75 votes), past polls