in reply to Re: local our?
in thread local our?

local and our are completely unrelated.

That's not true. local is about aliasing package globals, and our creates a package global in the package where that declaration occurs (and a lexical alias to that in the current scope), so they are related: they both act upon slots in the symbol table of a package. So they are related.

$ perl -E 'package Foo; local our $bar; package main; say for keys %Fo +o::' bar

and

$ perl -E 'our $bar = "foo"; say "1: $bar"; package Foo; { local our $ +bar = "quux"; say "2: $bar"; }; say "3: $bar"; package main; say "4: +$bar"; say "Foo::$_" for keys %Foo::' 1: foo 2: quux 3: foo 4: foo Foo::bar
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^3: local our?
by ikegami (Patriarch) on Apr 15, 2019 at 01:05 UTC

    The fact that they both can take a package variables as an argument doesn't make them related in any meaningful way.

    local is about aliasing package globals

    No. For example, my %h; local $h{x};. It's about making temporary backups of some values.

    our creates a package global

    No. our creates a lexical variable (that's aliased to the specified package variable).

    Simply mentioning the package var is what creates it.

    $ perl -le' print $::{var} // "[undef]"' [undef] $ perl -le'$var; print $::{var} // "[undef]"' *main::var
Re^3: local our?
by LanX (Saint) on Apr 14, 2019 at 21:15 UTC
    I think it's important to stay accurate:

    > our creates a package global in the package where that declaration occurs

    our will create a new STASH entry only, iff it doesn't already exist and it will not touch the value.

    > local is about aliasing package globals

    I can't see any "aliasing" process here, it's still the same underlying package variable.

    what do you call an "alias" here when doing local $main::bob; ?

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