Code:
sub build_sorthit {
# --------------------------------------------------------
# This function sorts a list of links. It has been modified to sort
# new links first, then cool links, then the rest alphabetically. By modifying
# the sort function below, you can sort the links however you like (by date,
# or random, etc.).
#
my (@unsorted) = @_;
my ($num) = ($#unsorted+1) / ($#db_cols+1);
my (%sortby, %isnew, %iscool, $hit, $i, @sorted);
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_isnew + ($i * ($#db_cols+1))] eq "Yes") and ($isnew{$i} = 1);
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
}
foreach $hit (sort {
($isnew{$b} and !$isnew{$a}) and return 1;
($isnew{$a} and !$isnew{$b}) and return -1;
($iscool{$b} and !$iscool{$a}) and return 1;
($iscool{$a} and !$iscool{$b}) and return -1;
if ($db_sort{$db_cols[$db_sort_links]} eq "date") {
($isnew{$a} and $isnew{$b}) and return &date_to_unix($sortby{$b}) <=> &date_to_unix($sortby{$a});
($iscool{$a} and $iscool{$b}) and return &date_to_unix($sortby{$b}) <=> &date_to_unix($sortby{$a});
return $sortby{&date_to_unix($b)} <=> $sortby{&date_to_unix($a)};
}
elsif ($db_sort{$db_cols[$db_sort_links]} eq "numer") {
($isnew{$a} and $isnew{$b}) and return $sortby{$b} <=> $sortby{$a};
($iscool{$a} and $iscool{$b}) and return $sortby{$b} <=> $sortby{$a};
return $sortby{$b} <=> $sortby{$a};
}
else {
($isnew{$a} and $isnew{$b}) and return $sortby{$a} cmp $sortby{$b};
($iscool{$a} and $iscool{$b}) and return $sortby{$a} cmp $sortby{$b};
return lc($sortby{$a}) cmp lc($sortby{$b});
}
} (keys %sortby)) {
$first = ($hit * $#db_cols) + $hit;
$last = ($hit * $#db_cols) + $#db_cols + $hit;
push (@sorted, @unsorted[$first .. $last]);
}
return @sorted;
}
Jerry Su