develooper Front page | perl.beginners | Postings from March 2002

RE: how to sort, in to out

Thread Previous | Thread Next
From:
Jenda Krynicky
Date:
March 21, 2002 06:24
Subject:
RE: how to sort, in to out
Message ID:
3C99FB21.16022.A1D68ED@localhost
From:  "David Gray" <david_gray@3b2.com>

> > I am trying to figure out an easy way to sort out a array of
> > numbers: 2 20 38 56 75 93 -17 -35 -53 -72 -90 Into the following:
> > -90 -72 -53 -35 -17 2 20 38 56 75 93 I have done the following:
> >   @x_step  = grep { ! $x_step_t{ $_ }  ++ } @x_step_t;
> >   @x_step = sort {$a == $b} @x_step;
> 
> You're really close:
> 
> @x_step = reverse sort {$a<=>$b} @x_step;
> 
>  -dave

It's silly to sort one way and then reverse. Simply turn over the test:

@x_step = sort {$b<=>$a} @x_step;

But I think he wanted ascending sort.

Jenda

=========== Jenda@Krynicky.cz == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain
I can't find it.
					--- me

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About