[EMAIL PROTECTED] (John W. Krahn) writes:

> "Michael R. Wolf" wrote:
> > 
[...]
> > Any value that is not false is true.  What 3 values indicate
> > false?
> 
> 
> Are you sure there are only three?   :-)
> 
> $ perl -le'
> print qq(undef is FALSE) unless undef;
> print qq("" is FALSE)    unless "";
> print qq("0" is FALSE)   unless "0";
> print qq(0 is FALSE)     unless 0;
> print qq(0e0 is FALSE)   unless 0e0;
> '
> undef is FALSE
> "" is FALSE
> "0" is FALSE
> 0 is FALSE
> 0e0 is FALSE

You caught me; very nice counterproof.  You were obvoiusly
right about the "0" (see "Camel citation below), but I'd
suggest that 0 and 0e0 are the same - they're both scalar
numeric zero.  I could be convinced otherwise if there's a
reason to make the distinction between these:

  scalar numeric float zero (0e0)
  scalar numeric int zero   (0)

I originally suggested 3 false values, you counterproposed
5, and now I'm counter-counterproposing 4.

I've modified the test (with answers) as below.

test> Any value that is not false is true.  What values indicate false?
test> 
test> string  -- _""____  _"0"___
test> 
test> numeric -- _0_____
test> 
test> other   -- _undef_
test>

When scoring it, I'll accept 0e0 instead of or in addition
to 0, but I'm not likely to get it since I won't mention the
distinction in class.  There isn't really an user-level
distinction between int and float like there is a
distinction between string/numeric and scalar/array.

FYI and BTW, here's a cut/paste from the "Camel Book"
(thanks to the CD).  It talks about true and false.  I've
found it easier to talk about false, then let the rest of
the universe be true.

Camel> Truth in Perl is always evaluated in a scalar
Camel> context. (Other than that, no type coercion is done.) So
Camel> here are the rules for the various kinds of values that a
Camel> scalar can hold:
Camel> 
Camel> Any string is true except for "" and "0".
Camel> 
Camel> Any number is true except for 0.
Camel> 
Camel> Any reference is true.
Camel> 
Camel> Any undefined value is false.



-- 
Michael R. Wolf
    All mammals learn by playing!
        [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to