View Full Version : Sorting
stevan
01-27-2007, 06:30 PM
I have never done cgi/perl
I have a question I have a links management script that when id adds a new link it does it alpha I want to change it to adding the new link to the bottom of the list
WHat would I look for >> Is there a standard coding for adding alpha ??
Thxs Steve
FishMonger
01-27-2007, 07:07 PM
There are several mehods that can be used to sort a list, we can't tell you what change(s) you need to make without seeing the code that is generating/outputting your links.
stevan
01-27-2007, 07:13 PM
I am guessing this is it ??
sub sort_links
{
if ($a->{STATUS} != $b->{STATUS})
{
$b->{STATUS} <=> $a->{STATUS}
}
elsif ($a->{POSITION} != $b->{POSITION})
{
$a->{POSITION} <=> $b->{POSITION}
}
else
{
lc($a->{NAME}) cmp lc($b->{NAME})
}
}
KevinADC
01-27-2007, 08:43 PM
sorting won't help unless you are using a date or something else to know which link is the newest one. If the links are in a text file, simply open the fie for appending and the newest entry is added at the end, then don't do any sorting of the list as it will be in chronological order already.
miller
01-28-2007, 01:57 AM
I am guessing this is it ??
sub sort_links
{
if ($a->{STATUS} != $b->{STATUS})
{
$b->{STATUS} <=> $a->{STATUS}
}
elsif ($a->{POSITION} != $b->{POSITION})
{
$a->{POSITION} <=> $b->{POSITION}
}
else
{
lc($a->{NAME}) cmp lc($b->{NAME})
}
}
Also, your equivalence testing in this sub is a waste of time. The compare operators (both numeric and string) already return 0 for equivalency. Simplify the sort code like this:
sub sort_links {
$b->{STATUS} <=> $a->{STATUS}
|| $a->{POSITION} <=> $b->{POSITION}
|| lc($a->{NAME}) cmp lc($b->{NAME})
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.