Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

choroba, I tried your syntax in my code, but I still get only a sort - not a reverse sort. I'm sure this is part of my overall difficulties with arrays in subroutines, but I'm stymied. Here's what I tried: my @SortedArray = sort ( reverse ( @PassedArray ) );

You misunderstood Choroba's point.

Choroba was telling you that your syntax (sort reverse ...) is equivalent to sort (reverse (...)), and that, when you do that, you are first reversing the order of the array and then sorting it (so that, in fact, first reversing is is totally useless).

What you want to do is the other way around: you want to sort the array and then reverse the order of the array thus sorted, which should be done, as others have already pointed with the following syntax:

my @sorted_array = reverse sort @unsorted_array;

which is first sorting the array and then reversing the order of the elements (think of the data as moving right to left, from @unsorted_array, through sort, then through reverse, into @sorted_array).

EDIT: Choroba answered while I was typing. I guess it is clear by now.


In reply to Re^3: reverse sort arrays in subroutines by Laurent_R
in thread reverse sort arrays in subroutines by JockoHelios

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (9)
    As of 2014-07-11 04:59 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (218 votes), past polls