I first questioned its utility in Why is 'our' good?. There are four basic problems that I know of with it. (I'm not counting the silly one that I pointed out above.)
  1. You have 2 packages in one file and didn't intend to use the variable from one package in the code for the other. This should be uncommon but not that uncommon.
  2. You have 2 files that access one package and you introduce synchronization issues. This is rarer than the first.
  3. A developer mistakenly tries to use our like you should use my. Now you have lots of room for a typo causing the variable accessed in one place to be different than the one in another, and strict.pm doesn't help.
  4. Using our is a gratuitous portability problem for people on Perl 5.005_05. Back when I first thought about this issue, that was a much bigger deal than it is today.
Its only advantage (in Perl 5) is that it involves slightly less typing. So while I consider it distinctly worse, it isn't really THAT bad.

As Larry pointed out in response to my node, its real purpose was a place to hang declarations about the variable in scope. For instance I believe one can say things like our Dog $spot is constant; and that has told Perl 6 that $spot must be something of type Dog, and in this lexical scope we are not allowed to change $spot. That's all functionality that couldn't be done with the old declaration.


In reply to Re^6: Using an "outer" lexical in a sub? by tilly
in thread Using an "outer" lexical in a sub? by cornballer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.