On 11/9/06, Zielfelder, Robert <[EMAIL PROTECTED]> wrote:
Greetings:

I have a sorting problem I need to solve but I'm not sure how to go
about it.  I have an application that dumps a file with a format like
this:

19JAN2006.1503
03JAN2006.1647
19DEC2004.0530
24MAR2003.1115

As you may have guessed, these are dates and times - timestamps for log
files from an application.  I want to be able to sort this list from
earliest to latest date.  I'm able to parse these into specific
categories (Year, Month, Day, Time) and can sort on any one category,
but I don't know how to sort by multiple categories.  Anyone have any
ideas?


Robert,

Do a search for information on "Schwartzian transform". This should
get you started:

my %month = ( JAN => '01', FEB => '02', MAR => '03', APR => '04',
               MAY => '05', JUN => '06', JUL => '07', AUG => '08',
               SEP => '09', OCT => '10', NOV => '11', DEC => '12' );

my @dates = qw/ 19JAN2006.1503
               19JAN2006.1303
               03JAN2006.1647
               03DEC2006.1647
               19DEC2004.0530
               24MAR2003.1115 /;

my @sorted = map {$_->[0]}
               sort {$a->[3] <=> $b->[3]}
               sort {$month{$a->[2]} <=> $month{$b->[2]}}
               sort {$a->[1] <=> $b->[1]}
               sort {$a->[4] <=> $b->[4]}
               map {[$_, /(\d\d)(\w\w\w)(\d\d\d\d)\.(\d\d\d\d)/]} @dates;

print join "\n", @sorted

__END___

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to