in reply to Tutorial::What is true and false?

At the very least please include undef as a false value not just 0 and ''.

I mentioned this a while back in the CB, as a *tweak*. A quick glance at the node might lead you into thinking undef isn't false, but if you read the node, it explicitly mentions that undef is false. So only the lazy will get caught.

Pedantic semantics: undef is not a value, it's the condition of lacking a value; so it is, in fact, true that the only false values are 0 and ''. I know it seems needlessly nitpicky, but it behooves us as programmers to keep 'boney was a warrior" , 7.178, and -18 in a conceptual box distinct from the one where we keep undef. Don't be fooled by the fact that there are operators that do stuff with undef into thinking it's a value like all the others.

Replies are listed 'Best First'.
(tye)Re: Tutorial::What is true and false?
by tye (Sage) on May 28, 2001 at 21:55 UTC

    I disagree with you on this. undef is a special false value in a Boolean context. The reason I say this is because in a Boolean context, undef doesn't get promoted to the empty string or zero like it does when used most other places.

    So undef isn't a numeric value nor a string value which is why you can't detect undef by comparing it to a string or a number. But there are other values that have these same problems (references being the most obvious). So, yes, we should keep undef in a different conectual box than strings and numbers, as we should references. But in the case of Boolean logic, undef is a distinct value in my book.

    And a discussion of "what is false" should mention it explicitly.

            - tye (but my friends call me "Tye")