|Perl Monk, Perl Meditation|
Re^4: 'require/use' scoping ("scope")by tye (Cardinal)
|on Jan 29, 2008 at 17:52 UTC||Need Help??|
I guess you need to scour the web and literature and implement your new personal definition of "scope" (which appears to only include "lexical scope of variables").
For example, Wikipedia knows that there are non-lexical types of scope including dynamic scope, that scope can apply to values not just variables, and that "a namespace is a scope". Although Foldoc unfortunately defines scope tersely in a way that implies only lexical scopes but this poor definition is contradicted by its own entries for dynamic scope and lexical scope.
A namespace is a scope and it does limit the effect of a variable; that's the point. You don't want your choice of variable names to affect the code that doesn't use your namespace. A package variable is limited in scope to only places that reference the owning namespace (either by declaring that they are in that package or by prepending the package name in order to access the variable). You can even access lexical variables outside of their scope if you take extra steps. The scope talks about where a simple $name will work.
local has nothing to do with the scope of the variable. It deals with the value
Yeah, that was what I said. But it is more accurate to say that local effects a new instance of a variable (and assigns that instance a new value) that has a dynamic scope. The value of this new instance can be changed but the instance will be destroyed when the program leaves its dynamic scope.
Update: Brian, think what you want. I heard about dynamic scope because the transition from Perl 4 to Perl 5 was a transition from only supporting dynamic scope to supporting lexical scope. If the authors of some of the Perl documentation now choose to not use "scope" except when talking about lexical scope, then I don't have a problem with that. But the programming world is not the Perl documentation and claiming "a namespace isn't a scope" is untrue. You can claim "the Perl documentation avoids referring to a namespace as a scope, preferring to reserve that term for only lexical scopes". But you don't get to define what the word "scope" means outside of that little world. You can even say "I wouldn't call a package a scope". I don't happen to live in the Perl documentation and care about more than how such chooses to use words.
You can choose to use a more narrow definition of "scope" and you won't even run into any problems so long as you realize you have narrowed the definition and so avoid boldly declaring what isn't included in your narrowed definition (without qualifiers to denote to others that it is a non-standard usage).