in reply to Re^3: the "our" declaration ?!!
in thread the "our" declaration ?!!

don't know what you mean, the following code is with curlies but produces different output for the two options.
use strict; no strict "vars"; # option1 #our $x; # option2 $x="main"; { package other; $x="other"; print $x; } print $x; __END__ 1: othermain 2: otherother

Cheers Rolf

Replies are listed 'Best First'.
Re^5: the "our" declaration ?!!
by ikegami (Patriarch) on Jan 20, 2009 at 22:16 UTC
    ...and don't nest your packages. I thought that went without saying.

    If you do nest your packages to share private variables, you should be using my, not our.

      There are still traps.
      package Foo; our $_; for (1..5) { print "$_\n"; }
        I didn't know that, thanks. But why would you do our $_;? It doesn't work for any other variable (because one would use my on the loop variable if it wasn't $_).
      with curlies, no nesting:
      use strict; no warnings; #no strict "vars"; # option1 our $x; # option2 { package one; $x="one"; print $x; } { package two; print $x; } __END__ 1: one 2: oneone
      I know that "use warnings" produces to "Use of uninitialized value" for option 1, but that's not the point here.

      Cheers Rolf

        You're forgetting about main, where the our is located