$MAX_HASH_SIZE = 10; #print "Title = " . $out_hash{$url}{TITLE} . "\n"; #print "EPOCH = " . $out_hash{$url}{EPOCH} . "\n"; #print "DESC = " . $out_hash{$url}{DESC} . "\n"; my $size = keys %out_hash; # remove the oldest element from the hash if ($size == $MAX_HASH_SIZE){ foreach $url (keys %out_hash){ push (@t,$out_hash{$url}{EPOCH}); } @t = sort { $a <=> $b } @t; # the oldest epoch should be at the end. # now find that key in the hash that has the oldest epoch and delete it. foreach $url (keys %out_hash){ if ($out_hash{$url}{EPOCH} == $t[$MAX_HASH_SIZE -1]){ $out_hash{$url} = undef; # Will that remove that key? } } } #### Now I need to sort the hash by epoch to print. #### It would be much nicer if I could sort the hash by the epoch. #### and only keep and print the most recent 10 keys.