in reply to Use of uninitialized variables?
I prefer to never initialize a variable as empty. Why? It is the best way to find out if you are actually using the variable in your code. Quick sample,
use warnings; my $retval = 0; warn "Return Value $retval\n";
You have not done anything with this value, and nothing gets reported as being a problem. If you do this,
use warnings; my $retval; warn "Return Value $retval\n";
You are going to get an uninitialized value warning, you will probably be saying WTF? Until you look and realize the code that you wanted was this,
use warnings; my $retval; $retval = get_value_from_subroutine(); warn "Return Value $retval\n";
It also reduces the amount of code that you have, I admit it is small, but do it a couple of hundred times, you get the idea.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Use of uninitialized variables?
by Zadeh (Beadle) on Jun 11, 2008 at 21:30 UTC | |
by Herkum (Parson) on Jun 12, 2008 at 14:27 UTC |