RE: easy way to add element to array

From: Bob Showalter (Bob_Showalter_at_taylorwhite.com)
Date: 10/29/04


To: "'brian.barto@spectrum-health.org'" <brian.barto@spectrum-health.org>,  beginners@perl.org
Date: Fri, 29 Oct 2004 15:10:56 -0400

brian.barto@spectrum-health.org wrote:
> Though about using a hash but I don't have a need for a Key/Value
> combination. I just need a list without duplicates. I suppose I can
> define the hash keys if they don't already exists and export the keys
> into an array with the keys function. Is that what you are hinting
> towards?

Yes, that's what I'm hinting at :~)

A hash would be called for if you need to do repeated tests to see whether
an element exists in the set. The downside to pulling the unique values with
keys() is that you lose the original order, if that matters.

Tie::Array::Unique will take care of the problem and preserve the order,
while letting you push entries onto the array without worrying about
creating duplicates.



Relevant Pages

  • RE: easy way to add element to array
    ... Though about using a hash but I don't have a need for a Key/Value ... I just need a list without duplicates. ... the hash keys if they don't already exists and export the keys into an array ... easy way to add element to array ...
    (perl.beginners)
  • Re: How can I create customized classes that have similar properties as str?
    ... duplicates of keys. ... of that hash as your keys. ... if str not in store: ...
    (comp.lang.python)
  • Re: Adding new value (in array) to existing key in a hash
    ... A more controlled sort. ... I only want to sort the keys where the values ... worried about the duplicates of coordinates, ... the sorted result for the following hash will be: ...
    (comp.lang.ruby)
  • Re: Suggestion for an AES Based Hash Function
    ... amateurs posting here seem to favour cyphers, I go for hash functions. ... Rather than trying to use a strong one-way compression function would ... I have used a fixed set of keys in two places. ... preferred to have the first round keys fixed and to start deriving ...
    (sci.crypt)
  • Suggestion for an AES Based Hash Function
    ... amateurs posting here seem to favour cyphers, I go for hash functions. ... Rather than trying to use a strong one-way compression function would ... The round function ... I have used a fixed set of keys in two places. ...
    (sci.crypt)