http://qs321.pair.com?node_id=11108308


in reply to Re^2: Unusual variable declaration
in thread Unusual variable declaration

You are not wrong in the details of what our accomplishes. But it is referred to as a declaration in the documentation for our:

An our declaration declares an alias for a package variable that will be visible across its entire lexical scope, even across package boundaries. The package in which the variable is entered is determined at the point of the declaration, not at the point of use.

Fortunately it does what it does regardless of what we call the behavior. :) It might be a case where there's not a one or few word name for the action our takes. But I do acknowledge your point; our is not a declaration in the say way that my is, or even int foo; in C. It would be nice if we had a word for it that isn't "relax the requirement for fully qualifying the name within a lexical scope under strict."


Dave

Replies are listed 'Best First'.
Re^4: Unusual variable declaration
by LanX (Saint) on Nov 04, 2019 at 22:25 UTC
    > our is not a declaration in the say way that my is

    Why?

    My is creating a pad entry for a lexically scoped variable, allocating and initializing it.

    A pad is a symbol table in a hash structure similar to a stash.

    Our is basically doing the same thing, apart from skipping to allocate space if the variable already exists.

    My's destruction at the end of scope is hardly a criterion for declaration.

    The pad is private, the stash is public and global. That's the basic difference.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      The point is that our is not doing the same thing. Not even basically. It might look like it does if you use it once, but as soon as you have several ours for the same variable in separate blocks it's clear our is not doing anything like my.

      Jenda
      1984 was supposed to be a warning,
      not a manual!