-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent parsing of parenthesized expressions involving masked outer variables with local/my #15461
Comments
From shmem@qwurx.deCreated by shmem@qwurx.deMasking variables is inconsistent between local() and my(). #!/usr/bin/perl -l In the line involving local(), the inner variable is modified. Looks like local is IMMEDIATE, while my is DEFERRED (in forth speak ;-). I consider this a bug or, at least, a breakage of orthogonality. Perl Info
|
From @mjdominus
Your expectation of 'my' is incorrect. Consider my $x = 1; Why does this work? `my` declares a second `$x` variable, but the The two '$x' tokens in the second line refer to two different In your example, the same thing is happening:
There are three $foo names in the second line. The `my $foo` is But the behavior is consistent, reasonable, and predictable. ================================================================ Now why is your example with 'local' different? 'my' and 'local' are not closely related. 'my' creates a new
I hope the situation is clearer now. |
The RT System itself - Status changed from 'new' to 'open' |
@cpansprout - Status changed from 'open' to 'rejected' |
From shmem@qwurx.dePlease take my apologies for filing this as a bug report, which was a From the keyboard of Mark Dominus [19.07.16,16:29]:
No; my expectations are not incorrect, but they don't fit the current
Yes, this is documented in perlsub: : The declared variable is not introduced (is not visible) until after Which is not quite correct. The declared variable is visible for our $foo = "foo"; Is there a compelling reason for my() being implemented this way? Would it not be more useful if my variables were visible (after This would resemble the semantics of local $x = $x where the current Aliasing a value or masking a variable or introducing a lexical variable
...whereas in local $x = $x both identifiers refer to the same variable The aliasing of the value slot via local() is carried out immediately, The visibility of my variables is deferred until after the current
0--gg- -- |
From zefram@fysh.orgGeorg Moritz wrote:
Your expectations are incorrect in that you are confusing lexical extent
No, the documentation is correct. Your example does not use the declared
Precisely where the name's scope begins is a somewhat-arbitrary language The main advantage of declarations working this way is that a variable Another benefit in some languages is that delayed introduction of the
The Perl implementation currently has built-in knowledge that scope Backcompat prohibits changing this for "my". One could implement it
No. In the context of Perl, the advantages each way are small, neither
"local" doesn't affect the scope of variable names at all. It's not
There is no ambiguity. -zefram |
Migrated from rt.perl.org#128669 (status was 'rejected')
Searchable as RT128669$
The text was updated successfully, but these errors were encountered: