I searched on the forum many times but I could get a real answer to my question: how can I make this sort by inhits???
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, %isincool, %isbest, $hit, $inhit, $i, @sorted, $column, $type);
foreach $column (@db_cols) {
if ($db_sort_links == $db_def{$column}[0]) {
$type = $db_def{$column}[1];
last;
}
}
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
($unsorted[$db_isinpop + ($i * ($#db_cols+1))] eq "Yes") and ($isincool{$i} = 1);
}
if ($type eq "date") {
foreach $inhit (sort {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a});
} (keys %sortby)) {
$first = ($inhit * $#db_cols) + $inhit;
$last = ($inhit * $#db_cols) + $#db_cols + $inhit;
push (@sorted, @unsorted[$first .. $last]);
}
}
elsif ($type eq "numer") {
foreach $inhit (sort {
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($inhit * $#db_cols) + $inhit;
$last = ($inhit * $#db_cols) + $#db_cols + $inhit;
push (@sorted, @unsorted[$first .. $last]);
}
}
else {
foreach $inhit (sort {
($isincool{$a} and $isincool{$b}) and $sortby{$b} <=> $sortby{$a};
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($inhit * $#db_cols) + $inhit;
$last = ($inhit * $#db_cols) + $#db_cols + $inhit;
push (@sorted, @unsorted[$first .. $last]);
}
}
return @sorted;
}
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, %isincool, %isbest, $hit, $inhit, $i, @sorted, $column, $type);
foreach $column (@db_cols) {
if ($db_sort_links == $db_def{$column}[0]) {
$type = $db_def{$column}[1];
last;
}
}
for ($i = 0; $i < $num; $i++) {
$sortby{$i} = $unsorted[$db_sort_links + ($i * ($#db_cols+1))];
($unsorted[$db_ispop + ($i * ($#db_cols+1))] eq "Yes") and ($iscool{$i} = 1);
($unsorted[$db_isinpop + ($i * ($#db_cols+1))] eq "Yes") and ($isincool{$i} = 1);
}
if ($type eq "date") {
foreach $inhit (sort {
&date_to_unix ($sortby{$b}) <=> &date_to_unix ($sortby{$a});
} (keys %sortby)) {
$first = ($inhit * $#db_cols) + $inhit;
$last = ($inhit * $#db_cols) + $#db_cols + $inhit;
push (@sorted, @unsorted[$first .. $last]);
}
}
elsif ($type eq "numer") {
foreach $inhit (sort {
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($inhit * $#db_cols) + $inhit;
$last = ($inhit * $#db_cols) + $#db_cols + $inhit;
push (@sorted, @unsorted[$first .. $last]);
}
}
else {
foreach $inhit (sort {
($isincool{$a} and $isincool{$b}) and $sortby{$b} <=> $sortby{$a};
$sortby{$b} <=> $sortby{$a};
} (keys %sortby)) {
$first = ($inhit * $#db_cols) + $inhit;
$last = ($inhit * $#db_cols) + $#db_cols + $inhit;
push (@sorted, @unsorted[$first .. $last]);
}
}
return @sorted;
}