On Aug 24, 9:55 am, [EMAIL PROTECTED] (Mr. Shawn H. Corey) wrote: > Paul Lalli wrote: > > 'our', like 'my', is lexically scoped. Its effects are terminated > > when the innermost enclosing block ends. So if you're using the same > > package variable in two different blocks, you have to use 'our' in > > each of them: > > 'our' is not lexically scoped; it is package scoped.
No. Package variables are package scoped. 'our' is lexically scoped. The effects of 'our' are gone as soon as the lexical scope in which it was used are gone. The package variable, of course, remains. > Once you declare a variable using 'our' you may use it anywhere in the > package. Incorrect. Once you declare a variable using 'our', you may use its shorthand name anywhere in the lexical scope of that declaration. You can ALWAYS use the fully-qualified name anywhere, regardless of strict, regardless of 'our'. $ perl -le' use strict; $main::foo = "hello world"; print $main::foo; { our $foo; print $foo; } print $foo; ' Variable "$foo" is not imported at -e line 9. Global symbol "$foo" requires explicit package name at -e line 9. Execution of -e aborted due to compilation errors. > See `perldoc -f our` for more details. You may wish to read that yourself... perldoc -f our An "our" declaration declares a global variable that will be visible across its entire lexical scope, even across package boundaries. > > #!/usr/bin/perl > > use strict; > use warnings; > > package Foo; > our $bar = 'Foo\'s bar'; # $bar is an alias to $Foo::bar Yes, but only for the LEXICAL SCOPE, which in this case is the entire file, since there was no enclosing block. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/