Skip to content

[doc] Request better documentation of "my" #18389

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

Closed
jidanni opened this issue Dec 7, 2020 · 4 comments
Closed

[doc] Request better documentation of "my" #18389

jidanni opened this issue Dec 7, 2020 · 4 comments

Comments

@jidanni
Copy link
Member

jidanni commented Dec 7, 2020

$ perldoc -f my
    my VARLIST
    my TYPE VARLIST
    my VARLIST : ATTRS
    my TYPE VARLIST : ATTRS
            A "my" declares the listed variables to be local (lexically) to
            the enclosing block, file, or "eval"...

OK but be sure to mention when its OK, and when not:

$ cat e.pl
use strict;
use warnings 'all';
my $e = 1;
my $e = 1;
{
    $e = 1;
    my $e = 1;
}
$ perl e.pl
"my" variable $e masks earlier declaration in same scope at e.pl line 4.

So only one of the three my's is bad.
So perldoc -f my needs to tell the user why. (Don't tell me why.)
Maybe the details are in perlsub. But we aren't using subroutines here,
so the user won't look there on his own.

@richardleach
Copy link
Contributor

Some text such as the following? (Which hopefully matches up with the error description in perldiag.pod.)
Variables should not subsequently be redeclared in the same scope or statement.

@jkeenan jkeenan changed the title [doc] [doc] Request better documentation of "my" Dec 9, 2020
@khwilliamson
Copy link
Contributor

Please submit a PR

@richardleach
Copy link
Contributor

PR coming shortly.

@richardleach
Copy link
Contributor

We added additional text in 9200002. Closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants