in reply to defined ? to be : not
Undef is a value, and one particular unique value, it is not a classification and it has nothing to do with bool/truth hood evaluation. Because its printable form is empty string, undef is false. In some systems, -1 is a "false" too (not in perl). Truthhood has to do with flow control. Undef is best used as a unique flag that can mean, error or no data, to separate empty string/0 from error or no data condition, 0 is valid data some times. Undef can't be stored to a file. Falsehood can be stored to a file.
Re^2: defined ? to be : not
by Anonymous Monk on Jun 18, 2012 at 06:49 UTC
|
Undef .. and it has nothing to do with bool/truth hood evaluation...
sorry, but you failed to get there :)
By your own explanation undef evaluates to false in boolean contexts, so yes, it has to do with bool/truth hood evaluation -- and it most certainly can be stored to a file
| [reply] |
Re^2: defined ? to be : not
by Don Coyote (Hermit) on Jun 18, 2012 at 07:29 UTC
|
Using definedness for flow control is one reason why I felt it would be suitable to use in the ternary operator example. I have also seen this used in cgi.pm where the ternary queries if the value is a reference as the method expects and proceeds accordingly.
An example of using undefinedness as a control flow can be seen in this node where I help a fellow monk with identifying and then filling initialised array indexes. Trying to edit HoAoA entries. This does not use ternary condition syntax.
Coyote
| [reply] |
|