http://qs321.pair.com?node_id=24110


in reply to i thought i knew 'our'...

'our' does _not_ declare a lexical scoped variable! What 'our' does is to say that the variables _name_ shall be lexical scoped. so:
use strict; { our $y = 17; print "inner: $y\n"; } print "outer: $y\n";
says that you are allowed to use the name '$y' in the block. Its name is lexical scoped. It does enter the name $y into the stash. Now, as you have discovered, without strict you may access $y's value. So, how to do it with strict on ?
use strict; { our $y = 17; print "inner: $y\n"; } print "outer: $main::y\n";
strict don't let you use globals (variables that live in the symbol table) unless:
  1. being told that it's actually ok (using 'our' or 'use vars')
  2. you fully qualify its name, as in $main::foo
So naturally, without strict you may access variables without fully quallifying them as in your last example.

Autark.

Replies are listed 'Best First'.
RE: RE: i thought i knew 'our'...
by jlistf (Monk) on Jul 24, 2000 at 20:47 UTC
    are you saying that 'our' lexically scopes the name, but globally scopes the value?
      Something like that, yes. Because the variables are put into the symbol table, they are global. In fact, 'our' has no semantical effect unless you use strict vars, so:
      our $foo = 1;
      and
      $foo = 1;
      shouldn't be different at all. It is first when you introduce use strict vars that the our keyword will have a different semantical effect.

      Autark.