in reply to Delete all hash keys except for n of them

This struck me as quite straightforward.
%hash = map { each %hash } 0..4;

Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Delete all hash keys except for n of them
by Anonymous Monk on Oct 26, 2004 at 00:43 UTC
    Even better!
    %a = (%a)[0 .. $n-1];
    Gautam
      Not only did I not see the code posted earlier, it was wrong too. Doh!
      %a = (%a)[0 .. $n*2-1];