Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (2)
As of 2024-04-20 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found