It was pointed out that whilst using 'd' to pack your offsets will work, when it comes to doing the sorting, you would have to unpack the values and do a numeric comparison as sorting numeric data in it's pack'd binary for doesn't work for packed floats/doubles.

Having previously extolled the virtues of sorting numeric data in it's binary form, that doesn't sit right, so here are a couple of routines that will pack and unpack a FP value < 2**53 to an 8-byte binary form that is sortable. along with some rudimentary tests:

#! perl -slw use strict; use Math::Random::MT qw[ rand ]; sub ftob64 { return pack 'NN', int( $_[ 0 ] / 2**32 ), int( $_[ 0 ] % 2**32 ); } sub b64tof { my( $hi, $lo ) = unpack 'NN', $_[ 0 ]; return $hi * 2**32 + $lo; } for ( 1 .. 1e6 ) { my $test = int( rand 2**53 ); my $b64 = ftob64 $test; my $float = b64tof $b64; if( abs( $test - $float ) > 1e-15 ) { printf "%31.f v %31.f => diff %31.31f\n", $test, $float, abs( $test - $float ); } } my @randomBin = map{ ftob64 int rand 2**53 } 1 .. 1e6; my @sortedBin = sort @randomBin; my @sortedN = map{ b64tof $_ } @sortedBin; $sortedN[ $_ ] > $sortedN[ $_ + 1 ] and die "Error: $_ : $sortedN[ $_ ] > $sortedN[ $_ + 1 ]" for 0 .. $#sortedN - 1;

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^10: Sort big text file - byte offset by BrowserUk
in thread Sort big text file - byte offset - 50% there by msalerno

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.