Since not specified, let's assume you throw in one year's worth of reports at a time, and that you can parse the reports into a hash of hashes, so that:
#!/usr/bin/perl use strict; # reports to sort - you will need to parse existing to build HoH my %report; # dummy data $report{'report_1'}{'date'} = '10/29/2001'; $report{'report_1'}{'content'} = 'whatever'; $report{'report_2'}{'date'} = '12/29/2001'; $report{'report_2'}{'content'} = 'whatever2'; $report{'report_3'}{'date'} = '4/29/2001'; $report{'report_3'}{'content'} = 'whatever3'; $report{'report_4'}{'date'} = ''; $report{'report_4'}{'content'} = 'whatever4'; # define quarters my %quarter = (1 => 'q3', 2 => 'q3', 3 => 'q4', 4 => 'q4', 5 => 'q4', 6 => 'q1', 7 => 'q1', 8 => 'q1', 9 => 'q2', 10 => 'q2', 11 => 'q2', 12 => 'q3'); my %sorted_reports; for (keys %report) { # grab month if ($report{$_}{'date'} =~ m|^(\d+)|) { # work out quarter # force number - covers 01/1 inconsistancy my $q = $quarter{$1+0}; # whack into hash of arrays push @{$sorted_reports{$q}}, $report{$_}{'content'}; } else { # no date push @{$sorted_reports{'undated reports'}}, $report{$_}{'content'} +; } } # now print (or whatever) # note can sort because 'u' follows 'q' foreach my $quarter (sort { $a cmp $b; } keys %sorted_reports) { # print quarter print "\n\n$quarter:\n\n"; # and reports print join "\n\n----------\n\n", @{$sorted_reports{$quarter}}; print "\n\n", '=' x 60; }
cLive ;-)

In reply to Re: sorting by quarterly calendar by cLive ;-)
in thread sorting by quarterly calendar by data67

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.