|Syntactic Confectionery Delight|
Sorting using coderef's, and passing parametersby the_slycer (Chaplain)
|on Aug 17, 2004 at 20:28 UTC||Need Help??|
the_slycer has asked for the
wisdom of the Perl Monks concerning the following question:
I'm in the midst of a rewrite of a piece of code that is completely unflexible. One of the things that I'm attempting to do in adding flexibility to the code, is allow sorting based on a coderef.
So, I have a many dimensional hash that I'm using to setup parameters for how something should work. I would like to have one of the (optional) keys along the way be a 'sort' key with a coderef as the value.
This is relatively easy to do, the problem comes in when I am attempting to call a sort routine that accepts parameters..
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..
This fails with a syntax error, as does:
and other variations of the sort.
I guess, because this is a new script, I could rethink how I'm building the list(s) that will need sorting, but my preference would be to somehow get the above going.
Thanks in advance for any advice.