|
|
| Don't ask to ask, just ask | |
| PerlMonks |
Re: Perl keywords for declaring variables: my, our and local???by krusty (Hermit) |
| on Mar 22, 2003 at 19:24 UTC ( #245201=note: print w/ replies, xml ) | Need Help?? |
|
our is a lexically scoped alias for a global variable. Will create the global if it didn't exist already. Results are: By default any global variables you create automatically populate the "main" symbol table, %main::. With a package declaration you could change which symbol table you are populating when you declare unqualified variables. But our is a lexical decalaration. In the case above the declaration was file scoped. That's why I still got something back when I gave it an unqualified print statement print "$a\n" after the package declaration. Don't forget just because it's a lexically scoped variable, it's still an alias for a global variable. Hence when I reassigned $a = "foo" with the our declaration, I blew away the old value. Any comments are welcome. Cheers, Kristina
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||