sorting ascending and descending

Discussion in 'Perl' started by Seansan, Jan 29, 2005.

  1. Seansan

    Seansan Guest

    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
    Seansan, Jan 29, 2005
    #1
    1. Advertising

  2. Seansan

    Joe Smith Guest

    Seansan wrote:
    > Hi there,


    This newsgroup is defunct.
    Use comp.lang.perl.misc instead.
    -Joe
    Joe Smith, Jan 30, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex
    Replies:
    0
    Views:
    454
  2. dwelden
    Replies:
    11
    Views:
    480
    Neil Cerutti
    Jan 4, 2007
  3. Chris Curvey
    Replies:
    18
    Views:
    1,248
    Patrick Maupin
    Apr 1, 2010
  4. Alex
    Replies:
    0
    Views:
    156
  5. Alex
    Replies:
    0
    Views:
    149
Loading...

Share This Page