Gossamer Forum
Home : General : Perl Programming :

Need help sorting by date.

Quote Reply
Need help sorting by date.
Can someone help me change this sort function, so I can pass in a date mm/dd/yyyy and have it sort by date in descending order?

Code:
sub sort_db{
foreach $curr (@results){
($key,@rest) = split(/\|/, $curr);
$max = @fields;

$code='$record{$key} = { key => "$key", ';

for($x=0;$x<$max;$x++){
$code .= "\$fields[$x] => \"\$rest[$x]\",\n";
} # End of for

$code .= '};';

eval $code;
} # End of foreach

$sort_on = "$fields[$sort]";

@results=();
foreach $rp (sort { chr($a->{$sort_on} + 97) cmp chr($b->{$sort_on} + 97) } values %record){
$new_rec = $rp->{key};
for($x=0;$x<$max;$x++){
$new_rec .= "\|$rp->{$fields[$x]}";
} # End of for
push @results, $new_rec;
} # End of foreach
} # End of sub sort_db


It's currently setup to sort alphabetically. What should I change to make it sort by date?
Subject Author Views Date
Thread Need help sorting by date. Ryan 3383 Feb 18, 2003, 1:00 AM
Thread Re: [Ryan] Need help sorting by date.
Paul 3252 Feb 18, 2003, 1:21 AM
Thread Re: [Paul] Need help sorting by date.
Ryan 3238 Feb 18, 2003, 10:01 AM
Post Re: [Ryan] Need help sorting by date.
Paul 3237 Feb 18, 2003, 10:31 AM