in reply to Re^2: Examples fo Where "our" is really needed
in thread Examples fo Where "our" is really needed

The whole point of the word "our" in English is that it indicates shared property, and more than one person us allowed to say it about the same object without an argument breaking out. In Perl the word "our" does not declare a variable, but a private view of a public variable. It is quite properly limited to the lexical scope that uses the view. Sure, you can throw two functions into the one artificial lexical (or class) scope to share one "our" declaration, but that's a trick that doesn't scale well to multiply intersected sharings. Even Fortran got that one right.
  • Comment on Re^3: Examples fo Where "our" is really needed

Replies are listed 'Best First'.
Re^4: Examples fo Where "our" is really needed
by ihb (Deacon) on May 06, 2005 at 01:24 UTC

    In Perl the word "our" does not declare a variable, but a private view of a public variable.

    That's why I said "declare the same variable twice" and meant exactly the same as you do but with different words. Regardless how one choose to paint the issue I don't like to do the same thing twice if I don't have to or have a good reason not to. If I can't use regular ways of scoping access to a global then I can't, but if I can, as in my example above, I really prefer to not repeat myself. The day I refactor my code and/or mistype the name in one "repeated" our I might very well be hunting reasons for my uninitialized warnings instead of getting the help from the compiler I could've gotten. I'm unfortunately not just hypothesizing.

    our has its uses, but I think that scattering out ours to tighten down the access scope for globals instead of create new scopes when that's possible/not inconvenient is an abuse rather than a use of our.

    ihb

    See perltoc if you don't know which perldoc to read!