For your sample data, the OPs specifications, should lead to an ordering of:

copy carpet soap error prawn emblem cabin echo pail engine reptile esk +imo skunk

Not:

carpet error prawn reptile emblem engine echo eskimo copy soap cabin p +ail skunk

Consider the OPs 3-part specification and the following:

orig pre-r sort-r pre-e sort-e pre-o sort-O + final cabin cabin copy + copy prawn prawn carpet + carpet pail pail soap + soap error error error + error reptile reptile prawn + prawn engine engine emblem + emblem copy copy cabin + cabin echo echo echo + echo soap soap pail + pail eskimo eskimo engine + engine carpet carpet reptile + reptile emblem emblem eskimo + eskimo skunk skunk skunk + skunk

The problem with your algorithm is, that is doesn't exclude those items that match the first criteria, from being considered by the second criteria, if the also match it; but the OPs specifications (emphasis added):

all the strings inside the array that contain an “r” and sort those in ascending alphabetical order. For the elements that are left, find the ones that start with an “e” and sort those by ascii value of their third character. And for the ones that are left reverse sort by their last letter alphabetically.

Your algorithm does not exclude items that contain an 'r' from being considered when processing items that start with an 'e'. Eg. 'error'.

Nor does it exclude items that contain an 'r', or start with an 'e', from being processed when reverse sorting "the ones that are left".


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^2: How to perform different sorts on multiple sections of items in the same array by BrowserUk
in thread How to perform different sorts on multiple sections of items in the same array by estreb

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.