in reply to Surprising result when using undef
I think I got too distracted by the way I was using undef inside if statement -- which is evaluating a variable or expression in boolean context -- and the fact that the expression is a test for numeric equality --
if ( $possibly_undefined_val_here == 0 )... because I've routinely used and understood something like if ( $possibly_undefined_val_here ) to evaluate to "falsey" when the variable is undefined. I hadn't thought about it evaluating to 0, such that the resulting 0 == 0 in the boolean test becomes true, but of course it is.
But I also see that basically I got balled up in seeing that what I wanted was to have a flag that said "OK, we're in production mode because we have a truthy value, so let's roll" rather than one that said "OK, let's not roll if we're in development mode, so check to see whether we have a truthy value as to that, and, in order to be sure we remembered the issue, let's check to see whether we explicitly set the development mode flag to be the digit one or the digit 0."
I'm afraid this kind of complicated, inverted thinking gets in my way a lot. How elegant and direct is the logic of testing for the truth of a production mode flag, like testing to be sure a link in a chain is in place.
Really appreciate this information!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Surprising result when using undef
by Marshall (Canon) on Feb 25, 2021 at 17:21 UTC |