Calling sort without a comparison function is nearly always the wrong thing to do. However, I can think of two exceptions to this.

The first exception is when you have no other goal but to iterate in an order that is merely repeatable, even if that order should happen to completely arbitrary.

Do you have any statistics -- real or made up -- about the percentage of sorts performed by programs in Perl (or any or all programming languages) that do not fit the criteria of your first "exception"?

Because after ~30 years of programming in which my gut feel is that 90% or there about of my programs have included a sort for some purpose or another, I can remember just 2 occasions when language dictionary ordering was a goal. One was an internal phone directory. The other was the 6 million records of West African Examination Council University entrance examination results.

At ~300 people, the first was sufficiently short that whether 'Mac...' came before, after or adjacent to 'Mc...' was irrelevant.

In the latter, which encompasses names from 5 countries: Ghana, Liberia, Nigeria, Sierra Leone, and the Gambia, with all their combined mixes of ethnic, religious, tribal and imperial languages, cultures and backgrounds, meant that it was impossible to get them to agree on a single correct collation. Hence, the reports produced for each country, and even different areas within the same country, all had to be ordered differently according to a custom collation.

That was a good many years ago, but I guarantee that there isn't anything on CPAN that would have handled any single one of the dozen or so collation sequences required.

My personal gut-feel assessment is that for 95% (and probably more) uses of sort in programs, the actual collation ordering used is immaterial. What's yours?


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: best sort by BrowserUk
in thread best sort by ag4ve

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.