The following code (or some derivation of it) should be what you want. Basically it goes through the hash once and builds an array-of-arrays to store the indexes of the files, broken down by duration. Then just iterates through that array to print out the results. :
#!/usr/bin/perl -w use strict; # maximal $ of minutes my $max_bucket=5; my %file; $file{1}{TITLE}='foo'; $file{1}{SIZE}='5'; $file{1}{VLENGTH}='0 days 0 hours 4 mins 5 secs'; $file{2}{TITLE}='bar'; $file{2}{SIZE}='92'; $file{2}{VLENGTH}='0 days 0 hours 4 mins 13 secs'; $file{3}{TITLE}='baz'; $file{3}{SIZE}='1'; $file{3}{VLENGTH}='0 days 0 hours 2 mins 23 secs'; # initialize stats array my @stat; for(my $c=0;$c<=$max_bucket;$c++){ $stat[$c]=[]; } # populate stats array my $k; foreach $k(keys %file){ my ($d,$h,$m)=$file{$k}{VLENGTH}=~/(\d+)\s*days\s*(\d+)\s*hours\s*(\ +d+)\s*mins/i; my $duration=$m+$h*60+$d*60*24; $duration=$max_bucket if($duration>$max_bucket); push @{$stat[$duration]},$k; } # iterate through stats array to print out counts for (my $c=0;$c<=$max_bucket;$c++){ print "there are ".(scalar @{$stat[$c]})." clips "; if($c==$max_bucket){ print "greater than $c mins :\n"; }else{ print "between $c and ".($c+1)." mins :\n"; } } # iterate through stats array to print out names for (my $c=0;$c<=$max_bucket;$c++){ print "Names of clips "; if($c==$max_bucket){ print "greater than $c mins : "; }else{ print "between $c and ".($c+1)." mins : "; } print "".(join ', ',map {$file{$_}{TITLE}} @{$stat[$c]})."\n"; }

In reply to Re: Numeric summarisation from data in a hash? by lhoward
in thread Numeric summarisation from data in a hash? by dmtelf

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.