The our keyword[edit | edit source]
our makes a lexical alias to a global package variable with the same name and the current package to be used in the current lexical scope, same as my or state. In contrast to these commands, however, our creates an alias to an already existing variable having the same name, and does not create a new one.
If the variable list VARIABLES of our has more than one element, the list has to be placed in brackets.
If more than one our with the same name are declared within the same lexical scope, Perl issues a warning, as it is the case with multiple my declarations, but they are seen as redundant.
An our declaration may have also a list of ATTRIBUTES with it. The exact semantics and interface of TYPE and ATTRIBUTES are still evolving. TYPE is bound to the use of the fields pragma, and ATTRIBUTES are handled using the attributes pragma. Starting from Perl 5.8.0 on, also via the Attribute::Handlers module can also be used.
Syntax[edit | edit source]
our VARIABLES our TYPE VARIABLES our VARIABLES : ATTRIBUTES our TYPE VARIABLES : ATTRIBUTES
Examples[edit | edit source]