Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Sort::Key::Radix::skeysort bug or user error?

by traceyfreitas (Sexton)
on Apr 16, 2012 at 07:54 UTC ( #965254=perlquestion: print w/ replies, xml ) Need Help??
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!

Comment on Sort::Key::Radix::skeysort bug or user error?
Select or Download Code
Re: Sort::Key::Radix::skeysort bug or user error?
by Anonymous Monk on Apr 16, 2012 at 08:50 UTC

    But I get a bunch of errors:

    :) Well, the code you posted doesn't use warning, so I don't see how you're getting those warnings :)

    #!/usr/bin/perl -- use strict; use warnings; my @magma = qw/ 39CE7A132F3CF 1E739E84CBCF3 339E84CBCF3C7 39CF4265E79E3 2739E84CBCF3C 339E84CBCF3C7 273D09979E78F 1CE7A132F3CF1 39E739E84CBCF 33CE73D09979E 3CE73D09979E7 279CE7A132F3C 339CF4265E79E 0E73D09979E78 /; use Sort::Key::Radix qw/ skeysort /; my @sortedIdx = skeysort { my $what = $_; warn "WHAT $what "; $what = $magma[$_] if not length $_ > length scalar @magma; return $what; } 0 .. $#magma ; use Data::Dump qw/ dd /; dd \@magma ; dd \@sortedIdx ; dd @magma[@sortedIdx]; __END__ $ perl what WHAT 0 at what line 23. WHAT 1 at what line 23. WHAT 2 at what line 23. WHAT 3 at what line 23. WHAT 4 at what line 23. WHAT 5 at what line 23. WHAT 6 at what line 23. WHAT 7 at what line 23. WHAT 8 at what line 23. WHAT 9 at what line 23. WHAT 10 at what line 23. WHAT 11 at what line 23. WHAT 12 at what line 23. WHAT 13 at what line 23. WHAT 39CE7A132F3CF at what line 23. WHAT 1E739E84CBCF3 at what line 23. WHAT 339E84CBCF3C7 at what line 23. WHAT 39CF4265E79E3 at what line 23. WHAT 2739E84CBCF3C at what line 23. WHAT 339E84CBCF3C7 at what line 23. WHAT 273D09979E78F at what line 23. WHAT 1CE7A132F3CF1 at what line 23. WHAT 39E739E84CBCF at what line 23. WHAT 33CE73D09979E at what line 23. WHAT 3CE73D09979E7 at what line 23. WHAT 279CE7A132F3C at what line 23. WHAT 339CF4265E79E at what line 23. WHAT 0E73D09979E78 at what line 23. [ "39CE7A132F3CF", "1E739E84CBCF3", "339E84CBCF3C7", "39CF4265E79E3", "2739E84CBCF3C", "339E84CBCF3C7", "273D09979E78F", "1CE7A132F3CF1", "39E739E84CBCF", "33CE73D09979E", "3CE73D09979E7", "279CE7A132F3C", "339CF4265E79E", "0E73D09979E78", ] [13, 7, 1, 4, 6, 11, 12, 2, 5, 9, 0, 3, 8, 10] ( "0E73D09979E78", "1CE7A132F3CF1", "1E739E84CBCF3", "2739E84CBCF3C", "273D09979E78F", "279CE7A132F3C", "339CF4265E79E", "339E84CBCF3C7", "339E84CBCF3C7", "33CE73D09979E", "39CE7A132F3CF", "39CF4265E79E3", "39E739E84CBCF", "3CE73D09979E7", )

    Apparently, on the first pass, $_ is the index, but subsequently it is the actual value --- the module interface doesn't exactly make sense to me, but if it really is faster ...

      the code you posted doesn't use warning, so I don't see how you're getting those warnings :)

      most probably by calling it with perl -w ... from outside the programme.

      Cheers, Sören

        most probably missing the gentle criticism, Cheers, Sören

        Yes, it was a subtle criticism about not providing Short, Self Contained, Correct Example. Yes, it was an effective question (all the parts were there), but you couldn't copy/paste/run the code and see the error, you had to add all the missing parts first

      Thank you for digging in to it! What I posted was actually just a few snippets. Doesn't everyone automatically use strict & warnings?? ;^)
Re: Sort::Key::Radix::skeysort bug or user error?
by salva (Monsignor) on Apr 16, 2012 at 12:09 UTC
    There was a bug on the module. A new version is already available from CPAN.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://965254]
Approved by moritz
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2014-09-16 19:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (45 votes), past polls