On Wed, 2003-09-03 at 21:24, Stas Bekman wrote: > [...] > >>In effect you use local() to undef the variable, instead of explicitly > >>initializing it. Why not doing this explictly? > > > > > > Firstly it's conceptually neater to use local. I want to think of the > > variable as local rather than as a global variable that needs to be > > explicitly reset. > > local is perl4-ism, nowadays it's used only for localizing special perl > variables, like $|.
I agree, using local, and especially "local our" is pretty strange. It may work, but I wouldn't want to encourage people to do that in their code. > To summarize: > > - move the perl4 lib solution to the perl_reference.pod > - suggest replacing my() with our() to avoid the closure, however this change > requires that the variables will be initialized before used in most cases > (example of 'open our $foo' which doesn't need to be initialized). you can > initialize variables by an explicit assignment of the value, or using the > 'local our' trick, which will initialize the variable to under, which is > probably not what you want. > - for users of perl < 5.6 suggest to use 'use vars' instead of 'our'. > - point to perl_reference.pod for other workarounds/solutions. May I also suggest telling users to pass arguments explicitly to subs, instead of doing it implicitly? Nearly all of the Registry-related bugs I see stem from people doing this: my $cgi = CGI->new(); foo() sub foo { $cgi->param(whatever)... } They accidentally create a closure this way and then wonder why their form values never change. Passing $cgi to foo() fixes the problem. - Perrin -- Reporting bugs: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html