Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: printing true false values

by HarshaHegde (Sexton)
on Dec 30, 2007 at 16:15 UTC ( [id://659629] : note . print w/replies, xml ) Need Help??


in reply to Re: printing true false values
in thread printing true false values

Thanks Jason and FunkyMonk, for the quick response. I did think of doing something similar: using the if else. However, by the definition of truth values in perl, 0 represents false and anything else represents true. So, if a boolean expression evaluates to true, it will return a 1 and if it evaluates to false, shouldn't it return a 0?

Replies are listed 'Best First'.
Re^3: printing true false values
by tinita (Parson) on Dec 30, 2007 at 16:43 UTC
    perlsyn.pod says:
    Truth and Falsehood
    The number 0, the strings ’0’ and ’’, the empty list "()", and "undef" are all false in a boolean context. All other values are true. Negation of a true value by "!" or "not" returns a special false value. When evaluated as a string it is treated as ’’, but as a number, it is treated as 0.
Re^3: printing true false values
by Somni (Friar) on Dec 30, 2007 at 16:26 UTC
    What values are considered true and false is not the same thing as what an expression evaluates to. Many Perl operators that evaluate to a boolean evaluate to 1 when true and '' (the empty string) when false.
Re^3: printing true false values
by bobf (Monsignor) on Dec 31, 2007 at 02:26 UTC
Re^3: printing true false values
by Anonymous Monk on Dec 31, 2007 at 14:18 UTC
    you could force numerical context