in reply to Re: How do I select a random key from a hash?
in thread How do I select a random key from a hash?

You also don't need int because indexing automatically int's it. {grin}

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

Replies are listed 'Best First'.
Re: Re: Answer: How do I select a random key from a hash?
by ysth (Canon) on Nov 04, 2003 at 10:09 UTC
    scalar keys %hash doesn't actually compute the keys (except for tied hashes).