Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1034612]
[Cow1337killr]: <p>stevieb, you should leave an insightful comment at https://plugins. idea/plugin/7796- perl</p>
[Cow1337killr]: (Oops. HTML paragraph markup not needed.)
[stevieb]: Cow1337killr yeah, you're probably right. I have communicated to the author directly, and here on his threads. It's a tremenous setup. With Devel::Camelcadedb , you get full perl debug support too
[stevieb]: so now I can use CLion with the Perl plugin and have a single IDE for Perl/C/C++. It'll make writing C/XS dists much easier
[stevieb]: Python too, but I leave work at work

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (9)
As of 2017-02-20 21:06 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (302 votes). Check out past polls.