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

Re^3: Real life uses for closures.

by runrig (Abbot)
on Feb 13, 2013 at 00:36 UTC ( #1018470=note: print w/ replies, xml ) Need Help??


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

Heh, reading that link, one of the basic things I've used closures for lately is filtering a list in different ways. I had one utility function that goes into a loop parsing email files from a directory (and if successful, finally returning the attachments from the one you want according to some parameters) and skipping files that it's already seen before. Then I found that in some particular case I needed to call the function multiple times and have it remember what it had seen from the previous call. So I turned the filtering function into a parameter, allowing you to maintain the hash of 'seen' email files outside of the loop in the main function (but keeping the original behaviour by default, which is what I want most of the time). Pretty basic example...but there it is.


Comment on Re^3: Real life uses for closures.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (15)
As of 2015-07-28 14:32 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 (256 votes), past polls