Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
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.
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 wandering the Monastery: (6)
As of 2014-09-24 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (245 votes), past polls