We don't bite newbies here... much | |
PerlMonks |
Re^3: closures: anonymous subs vs function templates?by Athanasius (Archbishop) |
on Dec 22, 2014 at 03:17 UTC ( [id://1110988]=note: print w/replies, xml ) | Need Help?? |
Hello Laurent_R, You understood me correctly, and it appears I was wrong: you have shown that it is possible to build a closure using function templates. But I note that, to get the syntax to work, you had to remove the local from the definition of *inner within sub make_adder, and that makes *inner a package global sub. In fact, what sub make_adder returns is simply the string *main::inner. So we can dispense with make_adder’s return value and the assignments to *f1 and *f2 altogether:
Output:
This approach is inferior to the standard technique (references to anonymous subroutines) in at least two ways:
Hope that helps,
In Section
Seekers of Perl Wisdom
|
|