Without making any attempt to be efficient, sorting by field n (a more normal term for your d(n) nomenclature), can be very simple. This sorts the data by the (additional) last character of the 4th field:

#! perl -slw use strict; my @data; while( <DATA> ) { if( /^\s/ ) { push @{ $data[ -1 ] }, split; } else { push @data, [ split ]; } } print "@$_" for sort{ substr( $a->[ 3 ], -1 ) cmp substr( $b->[ 3 ], -1 ) }@data; __DATA__ a1q b1w c1e d1r e1t f1y a2u b2i c2o d2p e2a f2s a3d b3f c3g d3h e3j f3k p3 q3 r3 s3 t3 u3 a4l b4z c4x d4c e4v f4b a5n b5m c5q d5w e5e f5r p5 q5 r5 s5 t5 u5 a6t b6y c6u d6i e6o f6p

Sorting by a date field is slightly more complex, but not much. I'd give an example, but as you've given dummy data, I'd have to make up the dates and I've no idea what format your data is in.

If you posted an example of your real data and explained what you are actually trying to achieve, rather than all this abstract stuff, you'd doubtless get much better answers.


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.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: Selecting the right data structure by BrowserUk
in thread Selecting the right data structure by thezip

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.