in reply to OUR declaration

To the best of my knowledge, it is a placeholder for things that are being thought about in Perl 6. The only convenience in Perl 5 is that it provides a way to cut out a use vars declaration for common globals (eg @ISA, $VERSION and @EXPORT_OK).

For more thoughts on why it is bad, see Why is 'our' good?. TimToady's response gives an idea why it might prove more useful in Perl 6.

Replies are listed 'Best First'.
Re^2: OUR declaration
by Anonymous Monk on Sep 23, 2006 at 03:16 UTC

    thanks. that was an excellent article.
    let me ask a follow-up question

    for the "normal" scenario of one file == one package;
    is there ever a case where our (instead of my) is needed?

      Needed? You need a global variable if you are going to set one with special meaning to Perl, or to an external module. But even then you don't need our to set those globals. (The most common globals that people do this with are @ISA, $VERSION, @EXPORT and @EXPORT_OK.)

      For instance a lot of people tend to write:

      package Foo; use strict; our @ISA = 'Bar'; ...
      instead of
      package Foo; use strict; use vars qw(ISA); @ISA = 'Bar'; ...
      so you can save a line. However you can solve that problem in other ways, for instance:
      package Foo; @ISA = 'Bar'; use strict; ...
      or
      package Foo; use strict; @Foo::ISA = 'Bar'; ...
      or in this case
      package Foo; use strict; use base 'Bar'; ...
      So our is always pretty gratuitous.
      If you want a global variable, i.e. one that can be read from other packages and does not go out of scope, then you either spell the whole thing out ($SomePackage::Variable) or use our so you can say ($Variable) within that file.