the_slycer has asked for the wisdom of the Perl Monks concerning the following question:
The above works fine, sorts based on $a/$b comparison/whatever. The problem is, when I want to sort (for example) a hash based on value. The sort routine needs the hash..$parameter_hash->{$this}{$value}{sort_by} = \&custom_sort; ... later, in some other subroutine ... my $sort_routine = $parameter_hash->{$this}{$value}{sort_by} || #other + standard sorts here; foreach (sort $sort_routine keys %{ $parameter_hash->{$this}{$value}{v +alue_list} }) { #do stuff }
This fails with a syntax error, as does:foreach (sort $sort_routine->(\%href) keys %{ $somehashref }) { #do stff }
and other variations of the sort.sort &{ $sort_routine }(\%href); sort &{ $sort_routine(\%href) };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting using coderef's, and passing parameters
by tilly (Archbishop) on Aug 17, 2004 at 22:48 UTC | |
|
Re: Sorting using coderef's, and passing parameters
by Fletch (Bishop) on Aug 17, 2004 at 20:32 UTC |