No such thing as a small change | |
PerlMonks |
Re^5: A short whishlist of Perl5 improvements leaping to Perl7 (Thought Experiment No.2)by LanX (Saint) |
on Nov 28, 2020 at 12:48 UTC ( [id://11124319]=note: print w/replies, xml ) | Need Help?? |
While the former thought experiment was closer to Python's behavior - all vars belong (mostly) to function scope - there is another possible approach. 1. any assignment to a new variable leads to an implicit my but only if their was no previous explicit declaration in a surrounding scope. This will replace former rules 1,4 and 5 all others still apply Hence we get the following 4 cases for explicit declarations with my or our
Surprises and pitfalls:
This is a very Perlish approach and avoids many edge cases. Of course this laziness comes with a price, introducing a new explicit declaration on file scope has an effect at the distance and could silently break subroutines
That's why this theoretical pragma must be optional. (Of course scoping the our inside a tight block would also prevent this.)
Cheers Rolf
In Section
Meditations
|
|