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.