CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
sorting the wrong way

 



mwaf
Deleted

Jun 25, 2000, 12:37 AM

Post #1 of 4 (490 views)
sorting the wrong way Can't Post

This is actually related to my 'sorting array' thread but I'll post another thread as I'm sure no one that hasn't followed the thread from the beginning would want to read it through to come to my latest question:

I have an array:
@array = ('mwaf','whatever','asdf')

@array = sort @info;
will result in @array being: "asdf mwaf whatever" which is fine, the problem is that I want it to be "whatever mwaf asdf", if there isn't any function that will to this directly how can I invert the order of values in an array effectively

If you want to read how my question is related to what I'm actually doing check http://www.perlguru.com/forum/Forum2/HTML/000464.shtml


TheGame+
Deleted

Jun 25, 2000, 3:01 AM

Post #2 of 4 (490 views)
Re: sorting the wrong way [In reply to] Can't Post

@array = reverse sort @info;


mwaf
Deleted

Jun 25, 2000, 3:30 AM

Post #3 of 4 (490 views)
Re: sorting the wrong way [In reply to] Can't Post

thanks!


Kanji
User / Moderator

Jun 25, 2000, 4:46 AM

Post #4 of 4 (490 views)
Re: sorting the wrong way [In reply to] Can't Post

You can also sort as you go in reverse order by just switching the order of comparison in the sort block.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

sort { $b cmp $a } @info;
sort { $b <=> $a } @info;</pre><HR></BLOCKQUOTE>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives