Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: sorting and indicies

by termix (Beadle)
on May 23, 2002 at 14:56 UTC ( #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?

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2023-06-01 23:09 GMT
Find Nodes?
    Voting Booth?

    No recent polls found