Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Re: Closure Over Scalar?by AnomalousMonk (Archbishop) |
on Feb 19, 2021 at 02:48 UTC ( [id://11128550]=note: print w/replies, xml ) | Need Help?? |
An approach that hasn't been mentioned so far is to encapsulate a function and its data-to-be-closed-over in a module. A my variable in a module is absolutely private unless a getter/setter is explicitly defined for it. All code in the module is executed at the point in script compilation at which the module is use-ed. Initialization and checking of any complexity can be done. (In some other languages, this is known as Compile Time Function Evaluation - CTFE - and is a Big Deal.) An extremely simple module with no exportation or OO can be used. CloseOver.pm:
Output:
Update: Minor edit for clarity. Give a man a fish: <%-{-{-{-<
In Section
Seekers of Perl Wisdom
|
|