in reply to sorting by quarterly calendar

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.