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.


In reply to Re: Sort::Maker not making sort by Corion
in thread Sort::Maker not making sort by macrobat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.