in reply to Sorting through a rollover

Hi, I'm sorry but I am not a native english speaker, so please forgive the poor question: Huh?!

What're you trying to do? Do you want to read the file and make a sorted output with the highest nr on top? Or otherways? As I assume your problem is that 00001 is smaller than 99999, but should be above it, because it's next?

Replies are listed 'Best First'.
Re: Sorting through a rollover
by onegative (Scribe) on Feb 10, 2005 at 17:20 UTC
    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.
      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
      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