You could do an in-place sort<super>*</super> but then you'd give up the speed of using Perl's built-in sort. The problem is that with almost any @foo=func @foo you wind up with two copies of @foo running around in memory.

If you want to write them to disk, yeah, you're pretty much gonna have to format the records one-per-line as you write them. If you're on a unix system, calling an external sort(1) might even be quicker than File::Sort (I'll bet it is).

A third consideration is this: if the elements are huge create an "index" array that just has the numbers 0..$#list in it. Then sort it like this:

for(0..1000) { push(@huge, {key=>rand, value=>'hlaghlagh'})} @index=(0..$#huge); @index=sort { $huge[$a]->{key} <=> $huge[$b]->{key} } @index;
At this point you can just use index to access the array elements in sorted order. Problem is in your case that you've just got arrays of references (the things you're sorting aren't huge, the list itself is). I'm not sure an @index array of Sv's is gonna be that much smaller than the references. If that were the case then you could just unwind it with $_=$huge[$_] for(@index); later.

12k elements doesn't seem like that much, though. Hrm.

<super>*</super>I always though an in-place sort would be a great use for scalar or void context sort. I haven't got the know-how to come up with the patch for that though.


In reply to Re: Sorting a large data set by clintp
in thread Sorting a large data set by jlf

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.