Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Sort::Maker not making sort

by Corion (Patriarch)
on Apr 18, 2007 at 20:44 UTC ( [id://610840]=note: print w/replies, xml ) Need Help??


in reply to Sort::Maker not making sort

Looking at the source code of Sort::Maker makes my eyes bleed, but it also seems that Sort::Maker uses a weird way of communicating errors - it sets $@ but doesn't die. So you could maybe change your error checking as follows:

die "No sort made: $@" if ! $sf;

When I do that with your code, I get the following "error":

make_sorter: Unknown option or key 'code'

which I consider to be fatal instead of to be the kind of warning people would prefer to hide. Also code is documented to be valid - maybe it depends on the order of arguments, as Sort::Maker really employs some nonstandard argument parsing. Maybe this also is another Perl "Best Practice" that is more a TheDamian Best Practice and should be avoided in general use.

Reading the documentation some more, it seems you have to give it some more arguments for sorting strings and/or numbers. The following code works for me:

#!/usr/bin/perl # foo.pl - This is just a test use strict; use warnings; use Sort::Maker; make_sorter( string => { code => sub { length } }, ST => 1, name => 's +ort_len', ) or die "$@"; my ( $foo, $bar ) = (qw/very_long short/); my @order = sort_len( $foo, $bar ); print @order;

Here I've wrapped the code => sub { length } in string => {...} - you should read the documentation if that is what you need or not, while I wash my eyes from looking at the code, the interface and the documentation.

Replies are listed 'Best First'.
Re^2: Sort::Maker not making sort
by macrobat (Beadle) on Apr 20, 2007 at 19:53 UTC
    Ah, and I thought the obfuscation of the doc was only in my head :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://610840]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2024-04-25 21:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found