our declarations can have additional features when compared with undeclared globals. But these are largely irrelevant.
our creates a lexical alias to a global variable (of the same name). That is, in
our $bar and
$Foo::bar refer to the same variable. However, the former is only available in a tight lexical scope.
our has a lexical effect, the alias can also shadow lexical variables with
our $foo = 42; # give some value my $foo = -1; # same name, different value say "my gives $foo"; our $foo; # reintroduce the alias; shadow lexical say "our gives $foo";
If you strip the
our declarations and run it without strict, this obviously won't give the output
my gives -1 our gives 42
our can take a bit extra declaration syntax, e.g. attributes:
use threads::shared; our $foo :shared;
You can also specify a type for usage with the
our Foo $foo;
This can't be done for global variables without