Thank you for your very interesting post.
One comment is that I sort of disagree in part with the Perldoc glossary entry you are quoting: to me, a closure does not necessarily have to be an anonymous function, you can do a closure with a named function, as shown in the following trivial (and not terribly useful) example:
which duly prints 50. The $add variable has supposedly fallen out of scope when the sub is called, but it still works, because the add_20 sub is closing over the $add variable.use strict; use warnings; use v5.14; { my $add = 20; sub add_20 { my $c = shift; return ($c + $add);} } say add_20(30);
Having said that, closures are mostly anonymous functions, because they are mostly useful as anon subs.
In reply to Re^2: closures: anonymous subs vs function templates?
by Laurent_R
in thread closures: anonymous subs vs function templates?
by 5haun
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |