![]() |
|
There's more than one way to do things | |
PerlMonks |
Re: Closure Over Scalar?by hippo (Bishop) |
on Feb 18, 2021 at 17:18 UTC ( #11128531=note: print w/replies, xml ) | Need Help?? |
You have received really good answers already (points all round) so if you don't mind I'll just don my consulting hat for a moment and provide a different viewpoint. You have a scalar variable $FIXED_STRING to which you assign a literal string once and never change it. Bonus points to you for choosing an appropriate name for your scalar! However, if this is a real indicator of your situation why not side-step the problem entirely by using a constant instead? In that case your block becomes:
and you do not need to worry about compile-time vs run-time or returning subs or any of that. This might be considered a work-around and that's just fine - sometimes a work-around is precisely what is required. Update: Haarg has spotted the flaw here and supplied a fix in his reply (++). 🦛
In Section
Seekers of Perl Wisdom
|
|