in reply to Re^4: complaint: always testing defined()
in thread complaint: always testing defined()

Quoting OP yet again (emphasis is mine) ...

Always having to check if the variable is defined before testing its value. It just seems soooo unnecessarily verbose.

I, personally, do get your point, and (would) have added the defined test myself.

The urge to silence the uninitialized variable warnings becomes rather strong (in most limited scope, of course), however, when more than a couple of defined tests exists in close proximity just to avoid the damned warnings. Yes, that does prompt me to check why the things are not defined, which sometimes results in anything fruitful.

But really, equality comparison of an undefined variable to anything else should just merrily produce the darned truth value without fuss.

  • Comment on Re^5: complaint: always testing defined()

Replies are listed 'Best First'.
Re^6: complaint: always testing defined()
by ysth (Canon) on Nov 05, 2007 at 03:36 UTC
    But really, equality comparison of an undefined variable to anything else should just merrily produce the darned truth value without fuss.
    Eww. That would be almost as bad as eq returning true, false, or undef (the latter if either operand is undef) ala SQL's NULL handling. I think the existing undef-becomes-""-or-0 is just fine.

      (In the proposed equality comparison of undef values) I would expect true only when both values are undef, false in any other case. That would result in much, w.r.t. Perl 5, POLA violation when warnings are off, namely 0 == undef and '' eq undef both returning false of course.

      One third day later ... Near "POLA violation" added the warnings usage, and corrected the given comparison results (in Perl 5 without warnings, results are true values).