-
Notifications
You must be signed in to change notification settings - Fork 561
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
top-level "my" vars visible in called functions #269
Comments
From [email protected]I'm running into a problem which I think is a bug, although it might <NTVERSION> This is perl, version 5.005_03 built for MSWin32-x86-object Copyright 1987-1999, Larry Wall Perl may be copied only under the terms of either the Artistic License or the Complete documentation for Perl, including FAQ lists, should be found on bash-2.02$ perl -V Characteristics of this binary (from libperl): The problem is that "my" variables declared at the top level of my #!/usr/local/bin/perl -w Runs perfectly happily, as follows: mike/tmp$ perl -w t2.pl Whereas I would expect to see: mike/tmp$ perl -w t2.pl Just as if there were no top-level declaration of $foo. I base this lexically-scoped private variables created with my() and th even more explicit statement in the "perlfunc" manual that A "my" declares the listed variables to be local (lexically) which says to me that the top-level outside-a-function bit of my #!/usr/local/bin/perl -w And indeed this version with an extra layer of function-call: #!/usr/local/bin/perl -w If I've misread the documentation, what _does_ a "my" declaration at Apologies if this is a FAQ -- I have read all the basic FAQs I can Thanks, Mike Taylor Site configuration information for perl 5.00404: Configured by stuart at Wed Jan 14 11:34:01 GMT 1998. Summary of my perl5 (5.0 patchlevel 4 subversion 4) configuration: Locally applied patches: @INC for perl 5.00404: Environment for perl 5.00404: |
From [Unknown Contact. See original ticket]
Ah badgers. Of course -- I see it all so clearly now. Thanks for the Mike Taylor |
From @pudgeAt 11.51 +0100 1999.07.28, Mike Taylor wrote:
For every function in that file, yes. A lexical scope works that way. my $x = 1; { sub foo { require 'bar.pl'; # $x is not visible in bar.pl
"the enclosing block" does not end where a new sub-block begins.
No, because scopes are determined at compile time, and $foo is not declared #!perl -w The fact that it is in a subroutine is irrelevant to the rules of scoping.
Well, here $foo is never declared in subfunc() or a lexical scope that
It means the entire file can see it. The file is one big scope. Sometimes -- |
Migrated from rt.perl.org#1090 (status was 'resolved')
Searchable as RT1090$
The text was updated successfully, but these errors were encountered: