in reply to Re: Scoping issue when sorting with subroutines
in thread Scoping issue when sorting with subroutines

Use something like this to create $by_sort_method:
sub create_sorter { my $contents = shift; return sub { # sort however you want here $contents{$a}{FOO} cmp $contents{$b}{FOO} }; } my $by_sort_method = create_sorter \%contents; foreach my $id (sort $by_sort_method keys %contents) { ... }