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?
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?
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?