Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • By custom sorting do you mean passing your own sorting method into the package method? Is this some restriction with the module itself or just a question of speed? perlfunc -f sort says if you prototype your sort method you can have it called as a proper sub,slower but depending on your data size it might not be much of an issue for you.
    use A;

    sub strange($$)
    {
            return -1 if $_[0] == 3;
            return 1 if $_[1] == 3;
            return $_[0] <=> $_[1];
    }

    A::try(\&strange)

    package A;

    sub try
    {
            my ( $method ) = (@_);
            my @A = sort $method ( 1 , 2 ,3 ,4 ,5 );
            print join(",",@A) . "\n";
    }
    1;
    • thanks - I came up with using @_ arguments last night (though I initially did {$func->($a,$b)} until I read the perlfunc entry about prototyping ($$).

      A benchmark of a simple sort on 1000 rows done over 10 million iterations shows a small ( Of course once you start like this, and realize you can create sort libraries you end up by creating complex sorts (like: "sort first by Jan/Feb/Mar order in one column, THEN by numeric order in another") with function composition, which does start to add some overhe

      --

      osfameron

      • Hmm, can't seem to edit that comment, once more, with preview! thanks - I came up with using @_ arguments last night (though I initially did {$func->($a,$b)} until I read the perlfunc entry about prototyping ($$).

        A benchmark of a simple sort on 1000 rows done over 10 million iterations shows a small (<10%) variation, bizarrely favouring the @_ version despite the extra level of indirection... I think that deciding you can't support custom sorting because using the overhead of @_ over $a,$b is too g

        --

        osfameron