Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: How can I access object data in a user defined sort cmp function?

by sundialsvc4 (Abbot)
on Jan 28, 2015 at 23:38 UTC ( #1114832=note: print w/replies, xml ) Need Help??


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.

  • Comment on Re^2: How can I access object data in a user defined sort cmp function?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114832]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2022-01-24 14:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (64 votes). Check out past polls.

    Notices?