david wrote: > Bob Showalter wrote: > > > Paul Kraus wrote: > > > Maybe I am misunderstanding but that seems to be the exact same > > > thing my does. > > > > No. my() creates a new variable. our() refers to a global variable. > > not sure what you mean by that. 'our' does create new variable if that > variable does NOT already exists in the current package's symble > table. otherwise, it shadows it.
No. See below. > > 'my' creates a new variable but only in the local lex. scope. the > largest lex. scope in Perl is file which means all variable tagged > with 'my' can never be visialbe outside of its current package > because 'my' does not put any variable in the current package's > symble table. OK, fine. As I said, "my" creates a new variable. > > the following shows just that: > > [panda@dzhuo]$ perl > my $a_variable = 1234; > /a_variable/ and print "$_\n" for(keys %::); > ^D > [panda@dzhuo]$ > > print nothing because $a_variable is not in the package's symble table > > the following, however, does find the variable: > > [panda@dzhuo]$ perl > our $a_variable = 1234; > /a_variable/ and print "$_\n" for(keys %::); > ^D > a_variable > [panda@dzhuo]$ > > because 'our' creates (if it doesn't already exists) and puts it in > the package's symble table. I think you're missing the point. Any reference to the symbol anywhere in the program "creates" the variable, in the sense you indicated here. For example: package Foo; our $x = 1; print "$_\n" for keys %Foo::; our $y = 1; This prints: x y So how did y get created "before" the our declaration? Ans: it is entered into the symbol table at compile time. Take out the "our"'s and you get the same results: package Foo; $x = 1; print "$_\n" for keys %Foo::; $y = 1; So the "our" does not create a variable. for instance: package Foo; use strict; $Foo::x = 1; our $x; print $x; # prints "1" "our" simply lets us refer to $Foo::x without the $Foo:: part. It does not create a new variable. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]