My personal understanding is that when a variable goes out of scope, it should be gone and gone, but you can still access it, which is the closure.
#
# Look at the example below.
# !/usr/bin/env perl-w Use Strict; { my$value'abc';} Print $value;
If this is the case:
Because $value does not exist after {} is exceeded, print becomes an undefined variable and an error occurs.
Let's look at one more example:
1 #!/usr/bin/env perl-w2 UseStrict;3 Subfunction_1{4 my $value='ABC';5 my $in _function_1=Sub{Print "$value \ n";};6 return $in _function_17 }8 9 my $value=function_1;Ten $value();
The results are as follows:
#
As can be seen, this $value should not exist, but also can access him, this situation is called "closure".
#
#
Perhaps you would like to say that this is not the return returned to him, because the first example does not return $value, so can not print?!
#
Personal view:
For the first example, if you return directly to $value, his value is returned, but the value is the same, which is not the same variable.
For the second example, the $value he visited was itself from beginning to end. (but internally, a copy of the variable may be created automatically)
#
#
Here's a quote from the word "Perl language Programming":
Represents a specific time when an anonymous function is defined in a particular lexical scope, it pretends to run in that scope,
Although it may later be called outside of this scope (but it is not pretending that it does run in that scope), it is called a "closure."
#
#
Personal advice according to the general function to understand the line, do not "too" care about the word "closure" the two words.
About Perl closures (personal understanding)