Our does an implicit declaration initialization of the package variable if it is new.
If you disagree, you should define what you mean with declaration in Perl.
update
"Declaration" is the act of defining type and attributes of a symbol for the compiler of a language.
That's especially important for languages where all symbols are barewords but Perl has sigils and variables are dynamically typed.
A "fully qualified name" in Perl like $pck::scl doesn't need to be declared for the compiler, because everything is known at compile-time. It's only initialized at first encounter into the STASH (symbol table) with a value (= undef by default)
So talking about the "declaration of a package var" is highly confusing.
BUT if you write our $var you are declaring for the compiler how to treat the symbol $var
To cite the docs:
An our declaration declares an alias for a package variable that will be visible across its entire lexical scope
Like with my this declaration is recorded in a hash like structure called a Pad which is an attribute of the scope (= surrounding "block" resp. function).
The big difference to my is that the our var is NOT destroyed (the ref is freed and the data erased from memory) at the end of the scope, because it is still referenced in the STASH of it's namespace.
I.e. next time you'll encounter an our $var in the same package it'll continue pointing to the same ref.
|