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 ;-)
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.