in reply to Re: Use of uninitialized variables?
in thread Use of uninitialized variables?
I like to use this for several reasonssub foo { my $retval = 0; <... lots of code here ...> return $retval; # This is the only return in the sub }
I find the 'classic C' style of declaring lots of variables at the top of your routine, then using them in the body, to be harder to follow. e.g.:... my $whatever = some_sub();
Worse if they're all global! I don't like jumping back and forth, or wondering where variables got their values (or what they were initialized as/from). Arguably if the code was done well enough in the first place it would already be pretty short and there would be no problem, but unfortunately I see this all the time. IMO it's more error-prone. If that's what you mean when you said "declare variables to minimize their scope" then I agree.my $var1; my $var2; my $var3; my @list; my %hash; ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Use of uninitialized variables?
by GrandFather (Saint) on Jun 11, 2008 at 23:10 UTC | |
|
Re^3: Use of uninitialized variables?
by chromatic (Archbishop) on Jun 12, 2008 at 06:39 UTC |