in reply to Re: Breaking The Rules
in thread Breaking The Rules
I would write:
use warnings; my $var=1; print $var;
Why the test? If $var is undef something much more serious is going on and I want to know about it.
Yes, I know this is a trivial example and you imply that there may be legitimate situations in which $var is undef. However I'm suggesting that if $var is undef when you are about to print its contents, then there is a flaw in the code. It may be as trivial as not having provided a default value, but providing the default value is important - it says to the reader that you have thought about the special case of the variable contents haven't been changed.
BTW, your second version is needlessly convoluted and will generate a warning (two if $var is undefined). KISS
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Breaking The Rules
by Unanimous Monk (Sexton) on May 31, 2006 at 15:43 UTC | |
by GrandFather (Saint) on May 31, 2006 at 16:49 UTC | |
by Unanimous Monk (Sexton) on May 31, 2006 at 19:35 UTC | |
by dsheroh (Monsignor) on Jun 01, 2006 at 15:48 UTC | |
by Anonymous Monk on May 31, 2006 at 20:47 UTC | |
by dsheroh (Monsignor) on Jun 01, 2006 at 15:41 UTC | |
by Unanimous Monk (Sexton) on Jun 02, 2006 at 18:01 UTC | |
by adrianh (Chancellor) on Jun 04, 2006 at 09:13 UTC | |
by Unanimous Monk (Sexton) on Jun 05, 2006 at 16:07 UTC | |
by tye (Sage) on Jun 01, 2006 at 17:06 UTC |