in reply to Re: When DOESN'T "Use of uninitialized value" show up?
in thread When DOESN'T "Use of uninitialized value" show up?
undef is false by definition in Perl and so is absolutely fine whenever in a boolean context.
"By definition" doesn't help explain it. For example, undef is interpreted as 0 by definition in a numeric context, but I nevertheless get "Use of uninitialized value" for 1 + undef.
perldiag, explaining the message, just says 'An undefined value was used as if it were already defined. It was interpreted as a "" or a 0, but maybe it was a mistake.' Since there is no qualifier on "used", I interpreted it to include use in a boolean context. I'd love to know where it might be clarified in documentation.
Hmm, now looking at it again, maybe the second sentence is the real rule (so the first is a misleading summary): 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)? If so, I still think that undef->{anything} not causing an error is a bad design, and other uses in an rvalue context might be. Personally, I want it to complain about any use of an undefined value.
What contexts are there for use of undef? Converting to a string, converting to a string, assignment, boolean, dereferencing via ->, ... any others?
Sub call?
$ perl -e 'my $x = undef; &$x("frog")' Undefined subroutine &main:: called at -e line 1.
I guess that's a conversion to a string instead of a bad reference -- like an eval rather than like undef->{...}.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: When DOESN'T "Use of uninitialized value" show up?
by ikegami (Patriarch) on Dec 16, 2011 at 08:08 UTC | |
by Tim McDaniel (Novice) on Dec 16, 2011 at 22:25 UTC | |
by ikegami (Patriarch) on Dec 17, 2011 at 05:06 UTC |