Why on earth would you want to effectively randomly delete the keys of a hash to get to a fixed number? You won't get the memory back if that is the reason. Are you sure you don't want a stack or a queue or a heap? Just an ordinary array? Here is another way to reduce the key numbers to $n.
%hash = map{ $_, $hash{$_} }(keys %hash)[0..$n-1];
cheers
tachyon
In reply to Re: Delete all hash keys except for n of them
by tachyon
in thread Delete all hash keys except for n of them
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |