http://www.perlmonks.org?node_id=722605


in reply to sorting function arcument to 'sort': Can I pass additional parameters?

I personally believe that you don't want to "pass in other arguments to the sorting sub" because the sub is meant to be used sort and sort() itself won't pass anything in. Chances are you want to use closures instead:

#!/usr/bin/perl use strict; use warnings; use 5.010; my @trans = ( sub { shift }, sub { ~ shift } ); my @unsorted = qw/foo bar baz/; for my $tr (@trans) { my @sorted = sort { $tr->($a) cmp $tr->($b) } @unsorted; say "@sorted"; } __END__
--
If you can't understand the incipit, then please check the IPB Campaign.