in reply to To initialise or not to initialise?
kiat, another good question, one that I have thought about often. Here's where I'm at now. I no longer initialize with a value, unless that value is to be used immediately and/or it helps me read what I'm doing:
—Brad
"Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton
I have found there is a difference between:my $ctr = 0; for ( 0 .. 5 ) { if ($foo[$_] eq $bar) { $ctr++; } }
andmy $variable;
ormy $variable = "";
depending on usage. In summary, I don't think there can be a hard a fast rule. Like many things, it depends on context and the readibility you need.my $variable = 0;
—Brad
"Don't ever take a fence down until you know the reason it was put up. " G. K. Chesterton
In Section
Seekers of Perl Wisdom