in reply to Re: fixing use of
in thread Error message when using 'our'
This prints "656".package main; my $var=6; sub foo { our $var; $var=5; } print $var; foo(); print $main::var; print $var;
What is means is, that within the subroutine foo, I can get to the package $var without having to use a full package name ($main::var). The our declaration makes it clear that within this lexical scope "$var" means the package variable, not the lexical $var that exists in the enclosing scope.
Sometimes there are uses for "our" inside of subroutines.
update: of course I meant $main::var
|
|---|