I think the following would work. I didn't try to adjust for null dates as I have no idea what your data format is. The snippet sorts by year, then by quarter, then by day.

use strict; use warnings; use Data::Dumper; my @sorted = map { [ $_->[0], join( '/', @{$_}[1..3] ), $_->[4] ] } sort { $a->[3] <=> $b->[3] || $a->[0] <=> $b->[0] || $a-> +[2] <=> $b->[2] } map { [ get_quarter( $_->[0] ), split( '/', $_->[0] ), $ +_->[1] ] } map { [ split( /\s/, $_, 2 ) ] } <DATA>; chomp @$_ foreach @sorted; print Dumper \@sorted; sub get_quarter { my @quarters = qw( 3 3 4 4 4 1 1 1 2 2 2 3 ); my ( $month ) = (split'/',$_[0])[0]; $quarters[ $month - 1 ]; } __DATA__ 10/23/2000 data1 foo bar baz 11/19/2000 data2 some stuff 08/11/2001 data3 what the heck? 04/30/2001 data4 this is getting dull 01/01/2001 data5 ??

Here's what it does:

Each array ref is going to have the quarter as the first element, the date as the second and the data as the third.

You're going to have to play with the above snippet as you need to account for null dates. Further, I really didn't test this for multiple quarters spanning multiple years (I assumed you'd have one fiscal year of data at a time).

Cheers,
Ovid

Vote for paco!

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.


In reply to (Ovid) Re: sorting by quarterly calendar by Ovid
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.