|Welcome to the Monastery|
Re: Help needed understanding global variables in Perlby broquaint (Abbot)
|on Mar 05, 2002 at 10:44 UTC||Need Help??|
> how exactly do I define (rather than declare) a global variable in Perl
> is there any kind of "super" use strict, which helps me catch typos that my programs may have?
> is there any way of defining a variable like C's static (i.e., a global variable with local scope)
Or you could use a closure to create the imitation of a static variable
> In fact, I have trouble understanding the difference between our ($i); and use vars qw($i);
The difference is that our() declares the variable into the current package and is visible for the rest of the lexical scope (in my opinion this is very icky and kinda anti-DWIM). Whereas use vars qw($x @y %z) just declares it's arguments into the current package, and doesn't mess with the lexical scope.
Update: changed explanation of our() vs use vars qw($x @y %z) per rob_au's note. Also realised why tilly has been knocking our() for so long ;-)