in reply to Using 'each' to get random (key, value) pair from hash returns "uninitialized value"
each visits each key in turn. There may still be keys in the hash, but there are no keys left to visit.
Before calling each(%hash) in scalar context, one needs to call keys(%hash) to reset the iterator.
Important: each does not return a random key. No assurances are made that there is no bias. "Random numbers are too important to leave to chance", but that's what you're doing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using 'each' to get random (key, value) pair from hash returns "uninitialized value"
by puterboy (Scribe) on Jan 28, 2011 at 21:11 UTC |