Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

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

by ptum (Priest)
on Dec 01, 2005 at 22:51 UTC ( #513471=note: print w/ replies, xml ) Need Help??


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

I will generally use a hash, with the keys reflecting the unique data elements. As I load the hash, I'll increment the value each time I encounter the key -- that way I have a unique set of keys, yet I can know (if I bother to check) about duplicate values in my original data set. This technique is good for when I am handling data that I need to be unique but might contain duplicates -- I can produce a warning or take some other action when I encounter the duplicate key (yet my main process, using the resulting hash keys, is unhampered by duplicates).


No good deed goes unpunished. -- (attributed to) Oscar Wilde


Comment on Re: To Hash or to Array--Uniqueness is the question.
Replies are listed 'Best First'.
Re^2: To Hash or to Array--Uniqueness is the question.
by eff_i_g (Curate) on Dec 01, 2005 at 22:54 UTC
    Thanks everyone! And to clarify, I am just capturing strings. I like your idea of counting ptum, it makes me feel better about using a hash and not "wasting" the value.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2015-07-08 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls