I'm not even sure if I understand your problem.  Looks as if you already
solved most of it.

[EMAIL PROTECTED] ([EMAIL PROTECTED]) wrote:
> Given the following text file:
> 
> My first idea is to rebuild the array with a 'sortkey' pre-pended to each
> record, and then sorting this temp-array by that key. Then I would remove
> the 'sortkey' and have a sorted array.

Looks good so far.

> 01spears  D12301spears  Dstuff
> 01spears  E12301xx      Eother stuff
> 01spears  R12301xx      Rmore stuff

...

> The real problem I have is with the "name" field being in one record only.
> The 'xx' values show that the name cannot be simply copied to the remaining
> records.

Here's the point I don't understand.  Copying the name is exactly what
you did in the key field you created.

> I've toyed with hashes of arrays, hashes of hashes, and can't work out the
> sorting routine.

If it's clear that the records always come in groups, work with arrays
of array-refs.  Store a complete group in an arrayref, place that into
your to-be-sorted array.  In the sort function, do the compare by
$a->[0] vs $b->[0].  Finally when dumping, have a nested loop over your
sorted array and it's content-array to output all the stuff.

Or did I miss the point of your question completely?   %-)

> I'm quite unsure of the 'best' or most 'efficient' way to do this.

YMMV, but depending on how many xx parts per group you have, you reduce
the number of keys that need sorting by at least a factor of 3 for the
examples you provided.  Sounds effective to me :-)

Mike

-- 
                     If we fail, we will lose the war.

Michael Lamertz          | [EMAIL PROTECTED] / [EMAIL PROTECTED]
    Nordstr. 49          | http://www.lamertz.net
    50733 Cologne        | Work: +49 221 3091-121
    Germany              | Priv: +49 221 445420 / +49 171 6900 310

Reply via email to