Perl Programming/Keywords/our

The our keyword
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 <tt>my</tt> declarations, but they are seen as redundant.

An <tt>our</tt> declaration may have also a list of <tt>ATTRIBUTES</tt> with it. The exact semantics and interface of <tt>TYPE</tt> and <tt>ATTRIBUTES</tt> are still evolving. <tt>TYPE</tt> is bound to the use of the fields pragma, and <tt>ATTRIBUTES</tt> are handled using the attributes pragma. Starting from Perl 5.8.0 on, also via the <tt>Attribute::Handlers</tt> module can also be used.