in reply to Re: How is it that I can see this package variable from another package without fully-qualifying its name?
in thread How is it that I can see this package variable from another package without fully-qualifying its name?
I don't know exactly what you mean when you say that an our binding "respects scope".
I do see that the declaration and definition of $var is at file scope. My understanding is that "package Bar" changes the package from Foo to Bar. Maybe I'm confusing "change of package" with "change of scope"?
I see that the following works as I'd expect:
#!/usr/bin/env perl use Modern::Perl; { package Foo; our $var = 42; # This is $Foo::var. } { package Bar; # This works, as expected. say "\$Foo::var: $Foo::var"; #say "\$var: $var"; # Fails, as expected. } #say "\$var: $var"; # Fails, as expected. say "\$Foo::var: $Foo::var";
Does that look like the correct way to keep packages separate in a single file?
(I realize that everything would also work as expected if I kept each package in its own module. And it would make them easily testable as well.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: How is it that I can see this package variable from another package without fully-qualifying its name?
by chromatic (Archbishop) on Apr 24, 2011 at 22:16 UTC |