Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^5: closure clarity, please

by vitoco (Friar)
on Nov 25, 2009 at 13:02 UTC ( #809334=note: print w/replies, xml ) Need Help??


in reply to Re^4: closure clarity, please
in thread closure clarity, please

Impressive! I could follow you step by step. After a second read (starting from the last step), I realized how the interpreter seems to work.

I think that I could simplify your work by excluding the "outer f" subroutine from the improved example, but as it is, is a great pedagogical example and explanation.

Thank you very much! And more thanks goes to ikegami.

BTW, this is not the way I program. I just wanted to understand what the OP was trying to explain. Everyday I learn something new of Perl's world. I'm not sure if I'm ready for Perl 6.

Replies are listed 'Best First'.
Re^6: closure clarity, please
by JadeNB (Chaplain) on Dec 07, 2009 at 16:39 UTC
    Here's another way of demonstrating the effect in your sample code, with hopefully a bit less “magic gluing”:
    sub g { my ( $a ) = @_; sub f { $a }; return sub { $a = $_[0] }; } push my @setters, g("Hi\n"), g("Bye\n"); print f; # => Hi $setters[0]("Bye\n"); print f; # => Bye $setters[1]("Hi\n"); print f; # => Bye (still)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://809334]
help
Chatterbox?
Corion idly wonders about creating a series of HTTP requests. There seems to be no framework to generate a series of HTTP requests, like "try all these requests"
[Corion]: This is vaguely inspired by that list of "nasty" strings, which I'd like to replace among HTTP parameters, just to see whether the application crashes, but also for easy downloading of a list of URLs etc

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2017-01-16 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (151 votes). Check out past polls.