Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > sorting ascending and descending

Reply
Thread Tools

sorting ascending and descending

 
 
Seansan
Guest
Posts: n/a
 
      01-29-2005
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


 
Reply With Quote
 
 
 
 
Joe Smith
Guest
Posts: n/a
 
      01-30-2005
Seansan wrote:
> Hi there,


This newsgroup is defunct.
Use comp.lang.perl.misc instead.
-Joe
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting ascending/descending with operator.attrgetter Chris Curvey Python 18 04-01-2010 02:23 PM
Sorting on multiple values, some ascending, some descending dwelden Python 11 01-04-2007 06:13 PM
Ascending and Descending Sorting of Columns in an ASP.NET DataGrid... Alex ASP .Net Datagrid Control 0 10-06-2003 04:52 PM
Ascending and Descending Sorting of Columns in an ASP.NET DataGrid... Alex ASP .Net 0 10-06-2003 04:52 PM
Ascending and Descending Sorting of Columns in an ASP.NET DataGrid... Alex ASP .Net Web Controls 0 10-06-2003 04:52 PM



Advertisments