I am surprised that nobody yet has suggested that you take a look at something relatively famous called the 'Schwartzian Transform', a quite powerful algorithm for sorting slightly complicated data such as the one you have, especially if you have a lot of data (where is is much faster, because it avoids duplicating some part of processing many times), but also quite practical in my view even if your data is quite small. It is sufficiently well known to have an article in Wikipedia (in many languages) and pages in many thousands of other sites. Just google it, or, if you prefer or are not completely convinced that Google is your friend these days, go to some initial pointers on it on Perlmonks:
What is "Schwarzian Transform" (aka Schwartzian)
Schwartzian Transform
Sorting dates with the Schwartzian Transform
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|