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

> 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

Replies are listed 'Best First'.
Re^5: Unusual variable declaration
by Jenda (Abbot) on Nov 05, 2019 at 11:19 UTC

    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!

        package Foo; $Foo::y = 42; sub foo { my $x; our $y; ... } sub bar { my $x; our $y; ... }

        Each of the two my $x declares a new variable. Both the our $y instruct the compiler to allow you to temporarily use a short name for the same global variable. They do NOT declare a variable!

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