You could load an AoA from your data file like this, which will retain the original ordering (if thats important), and allow you to sort the data pretty much any way you need to. Quite what you mean by

Data will be sorted on the d(n) field

is far from clear to me? Neither is why you think a "hashref" is relevant?

#! perl -slw use strict; my @data; while( <DATA> ) { if( /^\s/ ) { push @{ $data[ -1 ] }, split; } else { push @data, [ split ]; } } print "@$_" for @data; =output __DATA__ a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 a3 b3 c3 d3 e3 f3 p3 q3 r3 s3 t3 u3 a4 b4 c4 d4 e4 f4 a5 b5 c5 d5 e5 f5 p5 q5 r5 s5 t5 u5 a6 b6 c6 d6 e6 f6

Output

C:\test>junk4 a1 b1 c1 d1 e1 f1 a2 b2 c2 d2 e2 f2 a3 b3 c3 d3 e3 f3 p3 q3 r3 s3 t3 u3 a4 b4 c4 d4 e4 f4 a5 b5 c5 d5 e5 f5 p5 q5 r5 s5 t5 u5 a6 b6 c6 d6 e6 f6

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: 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.