<?xml version="1.0" encoding="windows-1252"?>
<node id="837669" title="Closure Explanation" created="2010-04-29 21:48:06" updated="2010-04-29 21:48:06">
<type id="115">
perlquestion</type>
<author id="670339">
bichonfrise74</author>
<data>
<field name="doctext">
I got this code from this article &lt;a href="http://www.perl.com/pub/a/2002/05/29/closure.html"&gt;perl.com&lt;/a&gt;.
&lt;code&gt;
sub make_counter {
    my $start = shift;
    return sub { $start++ }
}

my $from_ten = make_counter(10);
my $from_three = make_counter(3);

print $from_ten-&gt;() . "\n";
print $from_ten-&gt;() . "\n";
print $from_three-&gt;() . "\n";
&lt;/code&gt;

I tried to read the article on the explanation of the code above but I could not figure out how it is able to 'retain/remember' the old values. 
&lt;br&gt;Can someone further dissect or rewrite this code to show what is exactly happening?</field>
</data>
</node>
