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:
that's pretty brittle code but may be good enough for your needsmy %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 } }
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |