I tend to think of using "our $var;" as the equivalent of an external command in C/C++, a way to link a file global var across mulitple files.
This is correct; but in all files this variable should be declared with our. But there's more to variables declared with 'our':
- declaring a variable with 'our' creates a package global in the package in which it is declared
- the short name of this variable is visible throughout its lexical scope, even spanning packages
Example:
package Foo;
our $foo = 'foo'; # $Foo::foo now exists
package main;
print $foo,"\n"; # $Foo::foo, not $main::foo !
print $Foo::foo,"\n";
__END__
foo
foo
|