I'd suggest normalizing the strings in length with 
leading zeroes, and then use the string comparator.

  my @array =("3E1D302EDFDFDFDF", "3E1D", "4E1D302ECCCC6666",
"4E1D302ECCCC6667","4E1D302DCCCC6666", "3E");
  my $max = 0;
  for (@array) {
    my $len = length $_;
    $max = $len if $max < $len;
  }
  my @sorted = sort { my $a1=sprintf( "%0${max}s", $a ); my $b1=sprintf(
"%0${max}s", $b ); $a1 cmp $b1 } @array;
  print "$_\n" for @sorted;

Prints:
3E
3E1D
3E1D302EDFDFDFDF
4E1D302DCCCC6666
4E1D302ECCCC6666
4E1D302ECCCC6667

This is fine for small lists. But if you have big lists, you
should modify the above to make use of the Schwartian Transform
(see the FMTEYEWTK sorting docs for details).

--
Mike Arms


-----Original Message-----
From: Connop, Tim [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 12, 2002 4:43 AM
To: [EMAIL PROTECTED]
Subject: Sorting large hex values

Is there a module or method of handling large hex numbers?  I want to sort
them into largest first order, it works fine for number of 8 characters or
below, but anything above I get error messages:

Hexadecimal number > 0xffffffff non-portable at test.pl line 3.
Integer overflow in hexadecimal number at test 3.

#!/usr/bin/perl -w
@array=("3E1D302EDFDFDFDF", "3E1D", "4E1D302ECCCC6666",
"4E1D302ECCCC6667","4E1D302DCCCC6666", "3E");
my @array= sort { hex($b) <=> hex($a) } @array;
foreach (@array) {
    print "$_\n";
}

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to