I am not sure what to title this thread.
I would like to print the 10 most recent values accoding the the epoch in a hash, but epoch is not the key.
I guess I could put all of the epochs into an array. Sort the array. Then use another loop to find the key in the hash that corrosponds to the oldest epoch. Then set that key to undef. Then I would have to sort the hash again by epoch to print it. It seems that the solution would be to sort the hash by epoch and remove the last element but I dont know how to do it.
I am not sure what to call this type of hash. Therefore, I dont know what keywords to put in the title. Am I creating a hash of a hash?
Maybe I could store the values as $out_hash{$url}[0]...??
$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 d +elete 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.
In reply to How to print the 10 most recent (epoch) keys in a hash when epoch is not the key by kevyt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |