Perl Monk, Perl Meditation | |
PerlMonks |
Re: closures: anonymous subs vs function templates?by Laurent_R (Canon) |
on Dec 21, 2014 at 10:49 UTC ( [id://1110945]=note: print w/replies, xml ) | Need Help?? |
Both syntaxes use anonymous subs (but they are not really closures in your examples). The first syntax is writing the sub identifier into the symbol table, so that the sub can be called as a normal subroutine (without the -> dereferencing operator), while the second one is using a lexical variable which may have a limited scope and lifespan. Personally, I would tend to use only the lexical form (with scope) unless I had a good specific reason to do otherwise.
In Section
Seekers of Perl Wisdom
|
|