> is there any kind of "super" use strict, which helps me catch typos that my programs may have?
One of the reasons for using strict is to encourage the use of lexical variables and to move away from globals, which are can be a large cause of confusion to the unwary.
> is there any way of defining a variable like C's static (i.e., a global variable with local scope)
Not really. You can use a global variable in a local scope using the local() function.
Or you could use a closure to create the imitation of a static variable# use strict; $foo = "a string"; sub bar { local $foo; print qq(foo is now localized and empty "$foo"\n); }
> In fact, I have trouble understanding the difference between our ($i); and use vars qw($i);{ # creates a new lexical scope my $foo = "add text here - "; sub add_text { my $args = join '', @_; $foo .= $args; return $foo; } } # $foo now only referenced by &add_text
broquaint
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 ;-)
Update 2: also changed explanation of global variables per shotgunefx's note. /me thinks more research before posting might be an idea ...
In reply to Re: Help needed understanding global variables in Perl
by broquaint
in thread Help needed understanding global variables in Perl
by Anonymous Monk
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |