in reply to Re: Sorting through a rollover
in thread Sorting through a rollover

if

my @num = qw( 49998 49999 50000 50001 50002 500003)

you get

sorted: 50000 50001 50002 500003 49998 49999

There's got to be a link between the number shown on the page.

Update

How about

sort { abs( $a - $b ) > 200 ? $b <=> $a : $a <=> $b }


Y'know I just thought of something - looks like you're reading from a log of some sort

why would you have to sort at all?

Is it even necessary? (Just checking)

Replies are listed 'Best First'.
Re^3: Sorting through a rollover
by Roy Johnson (Monsignor) on Feb 10, 2005 at 20:30 UTC
    Or slightly more compactly (using trinary math instead of the trinary operator):
    (abs($a - $b) <=> $max_spread) * ($b <=> $a)
    where $max_spread is the maximum range you expect your numbers to cover before wrapping. 50_000 might be a better choice than 200.

    Caution: Contents may have been coded under pressure.
      The 200 was based upon the fact that he's showing 200 messages.

      either way, I think as long as it's less than the possible number of id's, it'll be ok

      (or maybe less than half?)