Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: reverse sort arrays in subroutines

by davido (Archbishop)
on May 21, 2013 at 21:39 UTC ( #1034612=note: print w/ replies, xml ) Need Help??


in reply to reverse sort arrays in subroutines

Are you trying to sort in descending order?

If so, you have a couple of choices. One, you can use a custom sort routine, eg:

my @SortedArray = sort { $b cmp $a } @PassedArray;

...or two, you can reverse the output of sort:

my @SortedArray = reverse sort @PassedArray;

The point I'm making is that reverse will act upon the sorted list. The way you have it, sort is acting upon a reversed list, which is incorrect. I hope I'm not missing your point. :) If that's not what you're asking, please clarify.

By the way, this isn't C++98 (vector.push_back()), you can populate your @TaR array like this: @TaR = ( 8, 2, 5, 4, 5, 6, 1, 8 ); ... and STDOUT is the default for print, so you don't usually need to explicitly mention it.


Dave


Comment on Re: reverse sort arrays in subroutines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-07-25 23:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls