Well ... getting the DBA to fix it should be the first step ... is there a SQL statement that you control for retrieving the data? If so, double checking for an ORDER BY clause would be helpful.

How big are the data files and how constant is the date field format? If small and always the same, you could go with the real cheap and easy approach by first reading in the data and then sorting it yourself. But first you need to get the date into a string easy to sort:

my %months = ( 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 %records; while( $line = <DATA> ) { chomp( $line ); my @line = split( /\|/, $line ); my @date = split( /-/, $line[-1] ); # bad practice here .. hopefully no dates from # last century (or next) my $year = "20" . $date[2]; my $mon = $months{$date[1]}; my $day = (split( /\s+/, $date[0]))[1]; # push onto array in case multiple events for date push( @{$records{$year.$mon.$day}}, $line ); } foreach my $date ( sort keys %records ) { foreach my $record ( @{$records{$date}} ) { # do your thing } }
that's pretty brittle code but may be good enough for your needs

-derby

In reply to Re: How to re-order badly formed dates within a delimited string? by derby
in thread How to re-order badly formed dates within a delimited string? by hmbscully

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.