traceyfreitas has asked for the wisdom of the Perl Monks concerning the following question:
UPDATE: Bug fix is uploaded. See below
If anyone has experience with the Sort::Key::Radix library, I would appreciate your input to see if I'm doing something blatantly wrong or if there's a bug in one of the methods I'm using.
I have an array of (uniform-length) hexadecmial strings:
@hexStr = ("339E84CBCF3C7", "2739E84CBCF3C", ...);
I would like to sort them and return a list of the sorted *indices* rather than just a list of the sorted hex strings. I used the keysort method from the author's non-Radix-based sorting library (Sort::Key::keysort) to successfully sort them with:
my @sortedIdx = keysort { $hexStr[$_] } (0..$#hexStr);
I would prefer to sort with Sort::Key::Radix method because it is *MUCH* faster (when using the working "ssort" method on strings directly) than other sort methods I've used and it seemed rather straight-forward:
my @sortedIdx = skeysort { $hexStr[$_] } (0..$#hexStr); # line 58
But I get a bunch of errors:
Argument "273D09979E78F" isn't numeric in array element at sortHexIndi +ces.pl line 58. Use of uninitialized value in subroutine entry at sortHexIndices.pl li +ne 58. Argument "339E84CBCF3C7" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "39CF4265E79E3" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "1CE7A132F3CF1" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "0E73D09979E78" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "2739E84CBCF3C" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "339CF4265E79E" isn't numeric in array element at sortHexIndi +ces.pl line 58. Use of uninitialized value in subroutine entry at sortHexIndices.pl li +ne 58. Argument "39CE7A132F3CF" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "3CE73D09979E7" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "1E739E84CBCF3" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "0F39CF4265E79" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "279CE7A132F3C" isn't numeric in array element at sortHexIndi +ces.pl line 58. Use of uninitialized value in subroutine entry at sortHexIndices.pl li +ne 58. Argument "33CE73D09979E" isn't numeric in array element at sortHexIndi +ces.pl line 58. Argument "39E739E84CBCF" isn't numeric in array element at sortHexIndi +ces.pl line 58.
I thought Sort::Key::Radix::skeysort would be appropriate for sorting strings, hence the "s". Am I doing something wrong or does this appear to be a bug?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort::Key::Radix::skeysort bug or user error?
by salva (Canon) on Apr 16, 2012 at 12:09 UTC | |
|
Re: Sort::Key::Radix::skeysort bug or user error?
by Anonymous Monk on Apr 16, 2012 at 08:50 UTC | |
by Happy-the-monk (Canon) on Apr 16, 2012 at 09:53 UTC | |
by Anonymous Monk on Apr 16, 2012 at 10:20 UTC | |
by traceyfreitas (Sexton) on Apr 16, 2012 at 18:07 UTC |