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

Yes, once I reach my max 99999 and the next event's transid is 00001, I need it to sort numerically greater than 99999 as to display:
00001
99999
99998
Thanks.

Replies are listed 'Best First'.
Re^2: Sorting through a rollover
by phaylon (Curate) on Feb 10, 2005 at 17:55 UTC
    Is there a reason why you only use 5 digits? The problem I see is that 99999 _is larger_ than 000001. It think it would only work with some kind of "cheating". I wouldn't find it very elegant, because your script has to guess.

    If it's in the lower range, 00001 is more likely the one on the bottom. If the numbers are near the top end, you can assume 00001 as first one.

    Possibilities I see:
    - Using one of the Neuronal Networking Modules on CPAN and train it to decide for you.
    - The index numbers do not have holes (eg: nothin' like 99800, 99801, 99803, ..)
    _ You make a algorithm which rates 0000n higher if the value processed before was larger and higher as, say 99990.
    - Don't let it begin again at 00001

    These are (imho) cool, easy, awful and clear :D

Re^2: Sorting through a rollover
by phaylon (Curate) on Feb 10, 2005 at 19:05 UTC
    Here's my try:

    Update: As I see, Razorblade was first :D
    use warnings; use strict; + my @middle = qw( 49998 49999 50000 50001 50002 50003 ); my @limit = qw( 99997 99998 99999 00001 00002 00003 ); + use Data::Dumper; print "MIDDLE\n"; print Dumper sort ro @middle; print "LIMIT\n"; print Dumper sort ro @limit; + sub ro { ( abs($a - $b) > 5000 ? $b <=> $a : $a <=> $b ) }
    gives me:
    MIDDLE $VAR1 = 49998; $VAR2 = 49999; $VAR3 = 50000; $VAR4 = 50001; $VAR5 = 50002; $VAR6 = 50003; LIMIT $VAR1 = 99997; $VAR2 = 99998; $VAR3 = 99999; $VAR4 = '00001'; $VAR5 = '00002'; $VAR6 = '00003';
    hope that helps;phay