XP is just a number | |
PerlMonks |
Re^5: Breaking The Rulesby Unanimous Monk (Sexton) |
on May 31, 2006 at 19:35 UTC ( [id://552912]=note: print w/replies, xml ) | Need Help?? |
In that case your example is gratuitiously idiosyncratic. The language provides a clean way of testing for a defined value. 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.
In Section
Meditations
|
|