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.)


In reply to Re^2: How is it that I can see this package variable from another package without fully-qualifying its name? by Anonymous Monk
in thread How is it that I can see this package variable from another package without fully-qualifying its name? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.