in reply to Re^4: Breaking The Rules
in thread Breaking The Rules
I guess that’s my own idiosyncrasy. To me, it seems odd to use 'defined $var', if what you really want to do is check whether the value of $var is undef. I'd be curious to know how many other monks would think '$var eq undef' is idiosyncratic.
Why bend over backwards to avoid using defined?
It comes down to what you actually want to test for. While '$var eq undef' vs 'defined $var' return the same result, which one should be used should depend on the purpose of the check. When writing my post, I choose between words that have very similar meanings to get the correct point across (like using 'spurious' rather than, say, 'bogus'). Same thing when choosing syntax.
While Its seldom a 'flaw in the code' if you need to check whether something has been defined, it is almost always a flaw in the code if use warnings generates an undefined used type warning. Comparing with undef is flawed, if only because you lose the virtue of turning on warnings. If I'm asking "what is the value of $var" and I get the response 'undef', to me that means '$var eq undef'
I don't dispute this point. If you use warnings, then '$var eq undef' will generate spurious warnings, so use 'defined $var' instead.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Breaking The Rules
by dsheroh (Monsignor) on Jun 01, 2006 at 15:48 UTC | |
Re^6: Breaking The Rules
by Anonymous Monk on May 31, 2006 at 20:47 UTC |