sorting ascending and descending
From: Seansan (sheukels=cuthere=_at_yahooo.co.uk)
Date: 01/29/05
- Previous message: Jeremy Morton: "Perl loops should use break, not last"
- Next in thread: Joe Smith: "Re: sorting ascending and descending"
- Reply: Joe Smith: "Re: sorting ascending and descending"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 29 Jan 2005 18:43:38 +0100
Hi there,
I am trying to sort an array hash on values. I pass a FORM tag and resolve
it to the array position to sort on. (see code below). Is there an easy way
to sort ascending or descending based on a new FORM value like ASC or DESC?
How would I add this functionality? I know I have to swap $a and $b, but I
have no idea where or rather how to add this to my code....
my $x=1;
if ($FORM{SORT} eq 'date') {$x=0;}
elsif ($FORM{SORT} eq 'email') {$x=5;}
elsif ($FORM{SORT} eq 'group') {$x=9;}
elsif ($FORM{SORT} eq 'url') {$x=4;}
foreach (sort{$LIST{$a}[$x] cmp $LIST{$b}[$x];} keys(%LIST)) {
(also posted alt.comp)
thx in advance, greets Seansan
- Previous message: Jeremy Morton: "Perl loops should use break, not last"
- Next in thread: Joe Smith: "Re: sorting ascending and descending"
- Reply: Joe Smith: "Re: sorting ascending and descending"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]