our $x;
I don't see a question either. Lexical scoping rules are pretty straight-forward as to what parts of the code are within some scope, so I bet you are confusing the scope of the variable itself (the value/data that $x points to) and the scope of this name for the variable (the binding).

With our, we are dealing with package variables, so the variable's data is always accessible (from any namespace) provided we use the fully-qualified name $package::x. our has no scope-induced side effects on the value at $x like local does -- i.e, the value at $x does not disappear when you leave the scope of our $x;.

What our really does is bind the (shorthand) name $x to the appropriate package variable location. The scope of this name binding is what is lexical, not the lifespan of the package variable or its contents. When you fall out of the scope, you lose access to the package variable via the shorthand name $x and that's it. But its value remains, and you can still get to it with its fully qualified name. Outside the scope, you are free to reuse the name $x for a lexical again.

It may sound like hair-splitting, but it's this important distinction that will help you understand the different scoping rules.

blokhead


In reply to Re: 'our' scoping by blokhead
in thread 'our' scoping 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.