in reply to Re^4: A short whishlist of Perl5 improvements leaping to Perl7 (Thought Experiment No.1)
in thread A short whishlist of Perl5 improvements leaping to Perl7
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
automine | effect | comment |
---|---|---|
|
|
not strict w/o automine |
|
|
not strict w/o automine |
|
|
backwards compatible |
|
|
backwards compatible |
Surprises and pitfalls:
automine | effect | comment |
---|---|---|
|
|
Doesn't compile Surprising for Pythonistas |
|
|
Unexpected result! Needs an explicit my $x = 0 at init to avoid implicit my |
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
use automine # our $var; ... sub foo { $var = shift; # not 'my $var' if explicit 'our $var' exists ... }
That's why this theoretical pragma must be optional. (Of course scoping the our inside a tight block would also prevent this.)
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
|
---|