I'm no expert on internals, but I'm pretty sure you could save at least 1/2 of your memory by changing @amp_a from being an array of anonymous arrays (which has an RV, an AV and 2 SV's per element) to a straight array of scalars (only one SV per element).
Then, instead of carrying around your cumbersome, unpacked data, you can just unpack in the sort:
my @sortamp = sort{ unpack(..., substr(...$a)) <=> unpack(..., substr( +...$b) } @$amp_a;
It might be slow, but (hopefully) you won't run out of memory.
You don't mention what platform you're running on, but if it's little-endian, this ought to work (because the sort key is an integer at the end of your data):
my @sortamp = sort{ reverse($a) cmp reverse($b) } @$amp_a;
(A straight string compare with the most significant bit in front.)
In reply to Re: Sorting data that don't fit in memory
by eg
in thread Sorting data that don't fit in memory
by jeroenes
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |