in reply to Pass additional params into sub which create sorting rules

I'd probably do that with a Schwartzian Transform, using a lexical to indicate which field I want the array to be sorted upon:
my @xx = ( 'dfb|cy|nmju', 'dfb|my|jhiho', 'aaa|zz|gggg' ); my $sort_field = 1; my @sorted_xx = map { $_->[1] } sort {$a->[0] cmp $b->[0]} map { [ (split /\|/, $_)[$sort_field], $_ ] } @xx;

which can be wrapped up in a sub into which to pass the delimiter and the $sort_field variable, as well as the array to sort (probably as a reference).

Of course, I could also set up a sub to pass to sort using a global flag

sub sorter { my @arr_a = split /\|/, $a; my @arr_b = split /\|/, $b; return $arr_a[$sort_field] cmp $arr_b[$sort_field]; }

but that would mean splitting each array element over and over for each comparison.

See also the recent thread Sorting a (very) large file.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}