in reply to Re: What's a reference? What's a variable? What's scope?
in thread What's a reference? What's a variable? What's scope?

What you just encountered is called a closure.

Uhm... No. It isn't. The rest of your explanation is pretty good though.

A closure is created when you create an anonymous subroutine that has access to lexically scoped variables that are outside the sub's scope but are available at the time the sub is defined. It's hard to explain but easy to show via an example:

my $counter = do { my $c; sub { $c++ } }; print &$counter, "\n" for 1..10;
-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: What's a reference? What's a variable? What's scope?
by BrowserUk (Patriarch) on Dec 28, 2002 at 19:38 UTC

    For the record, the quoted line was the first line of my post, for about 2 mins. I then withdrew it prior to seeing your reply.


    Examine what is said, not who speaks.