There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
(those declared with our or with a fully qualified name) According to the docs, variable symbols declared with our are lexical symbols (although the symbol table entry they refer to is a package global): our associates a simple name with a package variable in the current package for use within the current scope. When use strict 'vars' is in effect, our lets you use declared global variables without qualifying them with package names, within the lexical scope of the our declaration. In this way our differs from use vars , which is package scoped. What makes them look like non-lexicals is their auto-vivification of package globals. Consider:
and
The string evals show that our effectively allocates a symbol table entry for the package. The second example shows that after the compilation phase a symbol table entry main::foo has been allocated. I think of our as a hybrid beast. It is global in the sense that it generates a global, and a variable declared with our is an alias to the symbol table entry. It is lecical however in that it is transparent to multiple packages in a file. --shmem
In reply to Re^2: overview/tutorial on packages - creation and use
by shmem
|
|