in reply to Re: How can I access object data in a user defined sort cmp function?
in thread How can I access object data in a user defined sort cmp function?

“Schweee-e-ee-t!”   An extremely elegant solution.

++   ++   ++   ...

And, just for completeness, just for the “technically confused curious” passers-by (however many years from now ...) about “what in the heck a ‘closure’ is,” and with no attempt to steal anyone’s thunder:

A closure is voodoo an advanced technique that Perl makes very easy.   The local variable named $by_value is made to contain a reference to an anonymous sub which was created within a block of code in which a local variable named $self was “visible” to it, and in which it was known that this $self would continue to exist (with its then-present value) for the duration over which it will be needed.   (Namely:   “the lifetime of sub sort_hash_ref_keys_by_value.”)   This anonymous sub ... a “closure” ... will, rather magically, be able to “see” $self too, and can therefore refer to it in addition to $a and $b.   Each time the sort verb invokes this anonymous function, that function will magically be able to “see” $self, as though the sort verb, itself, were also located in the same block of source-code in which the closure-sub is defined.   The next best thing to being in two places at one time.

Masterful.   Brilliant.