sorting ascedning and descending

S

Seansan

Joe,

thx for your help. The only way to do this is to duplicate the keys list
into an array? This doesnt seem smart for long lists. But it works! thx

Seansan


repost:
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;}

my %fields = (date=>1, email=>5, group=>9, url=>4, default=>1);
my $x = defined $fields{$FORM{SORT}} ?
$fields{$FORM{SORT}} : $fields{default};
foreach (sort{$LIST{$a}[$x] cmp $LIST{$b}[$x];} keys(%LIST)) {

sub ascending { $LIST{$a}[$x] cmp $LIST{$b}[$x] }
sub descending { $LIST{$b}[$x] cmp $LIST{$b}[$x] }

my @keys = $FORM{DOWN} ?
sort descending keys %LIST :
sort ascending keys %list ;

-Joe
 
S

Sherm Pendley

Seansan said:
thx for your help.

Help on what? Who's Joe? If you're posting a reply, post a reply - don't
start a new thread for it.

Have you read the posting guidelines that appear here twice a week?

sherm--
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top