You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Drew Taylor <dt...@vialogix.com> on 2000/07/10 21:27:19 UTC

[OT] Re: Is variable initialization necessary?

Vivek Khera wrote:
> 
> >>>>> "DT" == Drew Taylor <dt...@vialogix.com> writes:
> 
> DT> My underlying concern is that each time the code is run, I get "clean"
> DT> variables. Every variable is a lexical. If that is enough to guarantee
> DT> emptiness on each run, then initialization is unnecessary (and in fact a
> DT> performance decrease).
> 
> If you initialize a variable at its declaration, will that
> initialization happen every time thru or will it be done similarly to
> a BEGIN block?  I think that's your real question.
I believe what you said is my question. Can I safely do this?

my @list;
foreach qw(field field2 field3) {
	push @list, $_;
}

I'm 99.99% sure snippet this will give me a clean @list each time it is
run. 

My next question is: do most of the modules submitted to CPAN initialize
variables? I read Chris' response, and I'm inclined to keep initializing
variables. One day I hope to submit CPAN modules, so is this a good
habit to get into? Sorry for getting so off-topic. 


-- 
Drew Taylor
Vialogix Communications, Inc.
501 N. College Street
Charlotte, NC 28202
704 370 0550
http://www.vialogix.com/