sorting ascending and descending

S

Seansan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top