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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.