But you are computing the keys twice, and that's expensive for large hashes. Perhaps this instead:
do { my @k = keys %hash; $k[rand @k] }
-- Randal L. Schwartz, Perl hacker
In reply to Re: Answer: How do I select a random key from a hash?
by merlyn
in thread How do I select a random key from a hash?
by tadman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |