in reply to 'our' scoping
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).our $x;
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
|
|---|