I tried that, and I think it might work, but it takes an extraordinary amount of time. So much so that I never actually saw it complete. To counter that, I tried extracting and deleting the keys in batches of 1000:

my @ordered; while( my $n = keys %hash ) { my @temp; for ( 1 .. $n < 1000 ? $n : 1000 ) { push @temp, scalar each %hash; } delete @hash{ @temp }; push @ordered, @temp; }

But it still takes an extraordinary amount of time.

Update: The above has a precedence problem with the ternary expression! And results in for loop operating from 1 to 1.

Add a set of parens and things go much more quickly:

my @ordered; while( my $n = keys %hash ) { my @temp; for ( 1 .. ( $n < 1000 ? $n : 1000 ) ) { push @temp, scalar each %hash; } delete @hash{ @temp }; push @ordered, @temp; }

BTW: If I ever manage to get the keys out of the hash and into an array without blowing memory, then I intend to use your Sort::Key to sort them in-place. But, there doesn't seem to be a an in-place version of keysort that doesn't take a callback?

I can use keysort_inplace{ $_ } @ordered;, but doesn't the callback slow things down?

I can use rsort_inplace @array and just assign the numbers reversed, but it seems there should be a sort_inplace() version?


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.
RIP an inspiration; A true Folk's Guy

In reply to Re^2: In-place sort with order assignment by BrowserUk
in thread In-place sort with order assignment by BrowserUk

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.