perl -we '$x = "global"; my $x = "local"; our $x; print $x'
global
Here there are two different $x variables; the global $x that lives in the symbol table for the main:: package, and a lexical $x that lives in a pad (a kind of temporary storage attached to each subroutine or source file (though one pad can have multiple variables of the same name with different scopes within the subroutine)). Normally in the scope of a my($var), $var will refer to the lexical variable. our($var) can be used to override that to the end of the enclosing block. | [reply] [d/l] [select] |