Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: sorting and indicies

by termix (Beadle)
on May 23, 2002 at 14:56 UTC ( [id://168780]=note: print w/replies, xml ) Need Help??


in reply to sorting and indicies

Your list is called "@list". This requires you to refer to its elements as $list[?] . This means that the sorting routine should be:

my @indicies = sort { $list[$a] <=> $list[$b] ) 0.. $#list;

If we read the line, it says:

  • @indicies is the new array
  • The sort is going to sort numbers from 0 to the highest index in "@list"
  • But the sorting comparision (the stuff in the curlies) is going to compare the values inside @list rather than the indicies themselves. However, it will reoder the indicies to create your new array.

Much greater detail is found in  man perlfunc and also on the sort documents on this site.

-- termix

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://168780]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found