[Chicago-talk] The "other" closure
Randal L. Schwartz
merlyn at stonehenge.com
Wed Dec 3 13:04:01 CST 2003
>>>>> "Jim" == Jim Thomason <jthomasoniii at yahoo.com> writes:
Jim> So, with only using that requirement, this is a
Jim> closure:
Jim> {
Jim> my $static = 0;
Jim> sub foo {
Jim> print STDERR "I've been called ", ++$static, "
Jim> times\n";
Jim> #...do interesting things
Jim> }
Jim> }
I always make sure such a block is a BEGIN block, so that (a) it
doesn't matter where I put it in my program - the initialization has
happened, and (b) it doesn't matter if I reexecute that code.
In fact, if you reexecute *that* code, you'll find a "won't stay shared"
error, I bet.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn at stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
More information about the Chicago-talk
mailing list