Closures again

Matts on 2002-08-08T16:16:42

The most interesting thing that came out of my thoughts earlier this week about closures was a description from Artur about how "require" actually works.

Apparently it loads the file, and turns it into a code reference with the body being the body of the anonymous sub. Then after it has been loaded it executes that code reference [*].

It's gems like that that I think would make people see some of the cool internal designs of perl. Yes, I think the above is a good idea - it's reusing one of perl's internal subsystems, and we like reuse, where it's sane.

So next time you're looking at a perl module, you can imagine it wrapped with "sub {" and "}->();" and you'll nicely confuse yourself!

[*] And then does some magic cloning that I didn't really understand ;-)