in reply to Limit the size of a hash

Based on the assumption that you're using a hash because you want all the records containing each of the top 10 values, this uses two passes. One to extract and subset the top 10 values. The second to print the records containing those values:

#! perl -sw use strict; open FH, '<', $ARGV[ 0 ] or die $!; ## First pass; find all the values my %vals; m[(\S+)$] and ++$vals{ $1 } while <FH>; ## Select the top 10 and put them in a hash for fast lookup. my %top10; undef @top10{ ( sort{ $b <=> $a } keys %vals )[ 0 .. 9 ] }; ## rewind for second pass seek FH, 0, 0; ## rewind ## And print them if they fit the criteria m[(\S+)$] and exists $top10{ $1 } and print while <FH>; ## close close FH;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.