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

I'd suggest using a counter variable rather than localtime (did you mean time?).

my $count = 0; my $test; unless ( exists $hash{$test} ) { $hash{$test} = $count++; }

This way, you can be sure you don't have duplicate values in the hash, even if you insert two elements at the same second.

To do the sorting, you'd need to do this:

sort { $hash{$a} <=> $hash{$b} } keys %hash;
  • Comment on Re^3: 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^4: Is there an easy way to assign guaranteed unique values to a simple array without looping through whole array?
by memnoch (Scribe) on Nov 29, 2007 at 23:20 UTC
    Thanks Kyle! I haven't used the spaceship operator yet....I'll have to look into that!

    memnoch
    Gloria in Excelsis Deo!