in reply to Re^2: When DOESN'T "Use of uninitialized value" show up?
in thread When DOESN'T "Use of uninitialized value" show up?
you get the warning if and only if, due to the operation it's being used in, Perl has to convert an undef value to a string ("") or number (0)?
Bingo.
Addition wants a number. If you don't pass a number, the value gets coerced into a number. Coercions from undef warn.
A truth test doesn't require or cause coercion, so there's no coercion that can warn.
What contexts are there for use of undef?
What does that mean? Are you asking what behaviour an operator can take when passed undef as one of its operand? Well, that's entirely up to the operator.
Personally, I want it to complain about any use of an undefined value.
That's so wrong. Paradoxically, making the use of undefined values always warn will have a net *drop* in useful warnings.
People use undefined values because they know warnings will occur if it's misused. If using undefined values always warns, a different value that never warns will be used instead.
Not to mention it's silly to have defined($undef), my $x = undef; and my $x = 123; warn.
You might be interested in no autovivfication;, though.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: When DOESN'T "Use of uninitialized value" show up?
by Tim McDaniel (Novice) on Dec 16, 2011 at 22:25 UTC | |
by ikegami (Patriarch) on Dec 17, 2011 at 05:06 UTC |