Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^3: Real life uses for closures.

by tobyink (Abbot)
on Feb 13, 2013 at 13:14 UTC ( #1018534=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Real life uses for closures.
in thread Real life uses for closures.

Technically none of the examples from Sort::MultipleFields employ closures; they just use anonymous functions. Closures "close over" a variable.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name


Comment on Re^3: Real life uses for closures.
Replies are listed 'Best First'.
Re^4: Real life uses for closures.
by DrHyde (Prior) on Feb 18, 2013 at 11:54 UTC

    Here's a closure from it ...

    $sortsub = sub($$) { $spec->($_[0]->{$field}, $_[1]->{$field}) || $oldsortsub->($_[0], $_[1]) }

    Lemme guess - did you just grep the code for /sub {/? :-)

      I didn't look at the source code at all - I was just referring to the usage examples in the pod.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2015-07-28 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls