Sorry but foreach should be:
foreach my $MyKey (sort keys %Unique ) {
Wags ;)
-----Original Message-----
From: Wagner-David
Sent: Tuesday, June 19, 2001 09:57
To: [EMAIL PROTECTED]
Subject: RE: populating an array with unique integers.
Use a hash vs array, use the number as a hash key. If key exists,
then get the next number until you have the number of unique numbers
desired.
next if ( exists $Unique{$RandomNumber} );
$Unique{$RandomNumber} = 1;
for printing:
foreach my $MyKey (sort keys %RandomNumber ) {
# print goes here
}
Wags ;)
-----Original Message-----
From: Scott Taylor [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 19, 2001 09:51
To: [EMAIL PROTECTED]
Subject: populating an array with unique integers.
I want to create an array, and populate it with random numbers, they should
be unique and sorted (I can sort at the output). I'm stuck at the unique
part:
generate a random number;
check if the number exists in the array,
if it exists generate a new one,
check again until a unique number is found.
once unique add too next place in array.
I think the perldocs are confusing me.
Thanks.
Scott.