in reply to Re: Mathematics skills
in thread Mathematics skills
If I do not explicitly want a specific initial value for a variable, I purposely leave it undefined so that I get a warning if I use it before I was planning to.
If I do not want an explicit initial value for a variable, I tend to set it explicitly to undef. It tends to pair up well with a latter test for definedness, and it also shows that I have considered that the variable containing an undefined value is actually, er, defined behaviour. Consider the snippet:
my $key = undef; for my $k( keys %h ) { $key = $k if $h{$k} eq 'foo'; } if( defined $key ) { # ... }
I find it makes it clearer to see that the variable starts out undefined and that the loop could set the variable to some value.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Mathematics skills
by Aristotle (Chancellor) on Oct 12, 2002 at 17:59 UTC |