in reply to Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?

If you don't want to use a tied hash, you can use an array and a hash. The hash to see whether or not a value has been seen and the array to store the values in order.
push(@array, $value) unless $seen{$value}++

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
  • Comment on Re: Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?
by memnoch (Scribe) on Nov 30, 2007 at 14:25 UTC
    Thanks Skeeve! I tried your code and see that it works, but I don't understand how the

    unless $seen{$value}++

    works with the autoincrement. Is there an explanation you could point me to?

    memnoch

    UPDATE: Okay, I understand it now....I didn't realize that the autoincrement was assigning a value to the hash key that was incremented each time the code runs into the same key. That's very clever! I'm all set. Thank you!

    Gloria in Excelsis Deo!