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.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery


In reply to Re^2: PadWalker's closed_over - but for our variables? (update: "declaration") by LanX
in thread PadWalker's closed_over - but for our variables? by LanX

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.