<?xml version="1.0" encoding="windows-1252"?>
<node id="495975" title="True or False? A Quick Reference Guide" created="2005-09-29 00:38:55" updated="2005-09-28 20:38:55">
<type id="120">
perlmeditation</type>
<author id="375665">
bobf</author>
<data>
<field name="doctext">
&lt;p&gt;
    &lt;a href = "#Truth and Falsehood"&gt;Truth and Falsehood&lt;/a&gt;&lt;br&gt;
    &lt;a href = "#Logical Tests: AND, OR"&gt;Logical Tests: AND, OR&lt;/a&gt;&lt;br&gt;
    &lt;a href = "#Exclusive OR: XOR"&gt;Exclusive OR: XOR&lt;/a&gt;&lt;br&gt;
    &lt;a href = "#References"&gt;References&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
    I wrote this quick reference guide for those times, late at night, when I forget how Perl treats various values.  (After debugging a troublesome &lt;c&gt;if( &lt;/c&gt;&lt;i&gt;&lt;c&gt;expression&lt;/c&gt;&lt;/i&gt;&lt;c&gt; )&lt;/c&gt; statement I occasionally rediscover that while both 0 and the empty string ('') are false, &lt;c&gt;0 eq ''&lt;/c&gt; is false but &lt;c&gt;0 == ''&lt;/c&gt; is true.)  This meditation is not meant to be an in-depth discussion of the concept of truth, and the tables are not comprehensive.  Nevertheless, I hope someone else finds this useful.
&lt;/p&gt;

&lt;a name = "Truth and Falsehood" id = "Truth and Falsehood"&gt;&lt;/a&gt;
&lt;h3&gt;Truth and Falsehood&lt;/h3&gt;
    &lt;p&gt;
        Identifying which values are treated as 'true' and which are treated as 'false' is straightforward once a few rules are established, but sometimes it is difficult to find exactly where in the docs a particular rule is documented.  The following quotes summarize the main points to keep in mind (from the ActiveState docs for 5.6.1).
        &lt;ul&gt;
            &lt;li&gt;
                "A scalar value is interpreted as TRUE in the Boolean sense if it is not the null string or the number 0 (or its string equivalent, "0"). The Boolean context is just a special kind of scalar context where no conversion to a string or a number is ever performed." (from [doc://perldata])
            &lt;/li&gt;
            &lt;li&gt;
                "When used as a number, undef is treated as 0; when used as a string, it is treated the empty string, ""; and when used as a reference that isn't being assigned to, it is treated as an error." (from [doc://perlsyn])
            &lt;/li&gt;
            &lt;li&gt;
                "The while statement executes the block as long as the expression is true (does not evaluate to the null string "" or 0 or "0")." (from [doc://perlsyn])
            &lt;/li&gt;
        &lt;/ul&gt;
    The table below summarizes these rules.  The text 'empty str' represents the empty string ("").  The first test (&lt;code&gt;if( $var )&lt;/code&gt;) reveals whether perl treats the value as true or false.  The results of the next two expressions (&lt;code&gt;if( defined $var )&lt;/code&gt; and &lt;code&gt;if( $var eq '' )&lt;/code&gt;) are fairly obvious, but they are included in the table to highlight the different interpretation of undef in each case.  Finally, the expression &lt;code&gt;if( $var == 0 )&lt;/code&gt; tests the value's numeric equivalency to 0.
    &lt;/p&gt;

        &lt;table border="1" cellpadding="2"&gt;
            &lt;caption&gt;&lt;b&gt;Truth tests for different values&lt;/b&gt;&lt;/caption&gt;
&lt;!-- --&gt;    &lt;colgroup span="7"&gt;
	            &lt;col width="28%"&gt;
	            &lt;col width="12%"&gt;
	            &lt;col width="12%"&gt;
	            &lt;col width="12%"&gt;
	            &lt;col width="12%"&gt;
	            &lt;col width="12%"&gt;
	            &lt;col width="12%"&gt;
	        &lt;/colgroup&gt;
&lt;!-- --&gt;    &lt;tr align="center" class="center"&gt;
                &lt;th&gt;&lt;/th&gt;&lt;th colspan="6"&gt;Result of the expression when $var is:&lt;/th&gt;
            &lt;/tr&gt;
            &lt;tr align="center" class="center"&gt;
                &lt;th class="wid28pct"&gt;Expression&lt;/th&gt;
                &lt;th class="wid12pct"&gt;1&lt;/th&gt;
                &lt;th class="wid12pct"&gt;'0.0'&lt;/th&gt;
                &lt;th class="wid12pct"&gt;a string&lt;/th&gt;
                &lt;th class="wid12pct"&gt;0&lt;/th&gt;
                &lt;th class="wid12pct"&gt;empty str&lt;/th&gt;
                &lt;th class="wid12pct"&gt;undef&lt;/th&gt;
            &lt;/tr&gt;
            &lt;tr align="center" class="center"&gt;
&lt;!-- --&gt;        &lt;td class="code" align="left"&gt;&lt;font face="courier"&gt;if( $var )&lt;/font&gt;&lt;/td&gt;
&lt;!-- --&gt;        &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr align="center" class="center"&gt;
                &lt;td class="code" align="left"&gt;&lt;font face="courier"&gt;if( defined $var )&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr align="center" class="center"&gt;
                &lt;td class="code" align="left"&gt;&lt;font face="courier"&gt;if( $var eq '' )&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
            &lt;/tr&gt;
            &lt;tr align="center" class="center"&gt;
                &lt;td class="code" align="left"&gt;&lt;font face="courier"&gt;if( $var == 0 )&lt;/font&gt;&lt;/td&gt;
                &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
            &lt;/tr&gt;
        &lt;/table&gt;

    &lt;p&gt;
        Several common values were left out of the table in an effort to keep the size manageable.  Those values include the following and are treated as noted (this is not an exhaustive list):
        &lt;ul&gt;
            &lt;li&gt;
                String zero ("0") is evaluated as numeric zero (0)
            &lt;/li&gt;
            &lt;li&gt;
                These values are interpreted as strings (like '0.0'):
                &lt;ul&gt;
                    &lt;li&gt;'0E0' (exponential)&lt;/li&gt;
                    &lt;li&gt;'00' (octal)&lt;/li&gt;
                    &lt;li&gt;'0x0' (hexadecimal)&lt;/li&gt;
                    &lt;li&gt;'+0' (positive), '-0' (negative)&lt;/li&gt;
                    &lt;li&gt;' 0' (spatial), '0\n' (linear)&lt;/li&gt;
                    &lt;li&gt;'.0' (fractional), '0.' (periodic)&lt;/li&gt;
                &lt;/ul&gt;
                See [tye]'s poll, [id://464548], for others.
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/p&gt;

&lt;a name = "Logical Tests: AND, OR" id = "Logical Tests: AND, OR"&gt;&lt;/a&gt;
&lt;h3&gt;Logical Tests: AND, OR&lt;/h3&gt;

    &lt;p&gt;
        Using the table and rules above, the outcome of a logical AND or a logical OR test can be predicted.  In Perl these operators do not simply return 0 or 1, however.  Instead, they return the last value that was evaluated in the expression, which is usually only tested for truth (using the table and rules given above) so the actual value is ignored.  Due to the short-circuiting nature of the operators, the returned value can be either the first or last value in the expression.  This behavior is documented in [doc://perlop]:
        &lt;ul&gt;
            &lt;li&gt;
                "Binary ``&amp;&amp;'' performs a short-circuit logical AND operation. That is, if the left operand is false, the right operand is not even evaluated."
            &lt;/li&gt;
            &lt;li&gt;
                "Binary ``||'' performs a short-circuit logical OR operation. That is, if the left operand is true, the right operand is not even evaluated."
            &lt;/li&gt;
            &lt;li&gt;
                "The || and &amp;&amp; operators differ from C's in that, rather than returning 0 or 1, they return the last value evaluated."
            &lt;/li&gt;
        &lt;/ul&gt;
        The tables below list the return value for logical AND (&amp;&amp;, and) and logical OR (||, or) operations for the values tested above.  The values are colored according to whether they are interpreted as &lt;font class="istrue" color="blue"&gt;true&lt;/font&gt; or &lt;font class="isfalse" color="red"&gt;false&lt;/font&gt; (as given in the table above).  In these tables, 'a string' has been replaced by 'A string' and 'B string' so it is clear which value is returned.
    &lt;/p&gt;

            &lt;table border="1" cellpadding="2"&gt;
                &lt;caption&gt;&lt;b&gt;Logical AND tests for different values: A &amp;&amp; B&lt;/b&gt;&lt;/caption&gt;
			    &lt;colgroup span="7"&gt;
		            &lt;col width="16%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		        &lt;/colgroup&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;th&gt;&lt;/th&gt;&lt;th colspan="6"&gt;Value of B&lt;/th&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;th class="wid16pct"&gt;Value of A&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;'0.0'&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/th&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;'0.0'&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;A string&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;empty str&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;undef&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;

            &lt;br&gt;

            &lt;table border="1" cellpadding="2"&gt;
                &lt;caption&gt;&lt;b&gt;Logical OR tests for different values: A || B&lt;/b&gt;&lt;/caption&gt;
			    &lt;colgroup span="7"&gt;
		            &lt;col width="16%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		        &lt;/colgroup&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;th&gt;&lt;/th&gt;&lt;th colspan="6"&gt;Value of B&lt;/th&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;th class="wid16pct"&gt;Value of A&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;'0.0'&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/th&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;'0.0'&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;A string&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;A string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;A string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;A string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;A string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;A string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;A string&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;empty str&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;undef&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;0.0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;B string&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;

&lt;a name = "Exclusive OR: XOR" id = "Exclusive OR: XOR"&gt;&lt;/a&gt;
&lt;h3&gt;Exclusive OR: XOR&lt;/h3&gt;

    &lt;p&gt;
        The result of an XOR expression (minimally documented in [doc://perlop]) can also be predicted using the truth table given above.  The following table summarizes the results for the values tested above.
    &lt;/p&gt;

            &lt;table border="1" cellpadding="2"&gt;
                &lt;caption&gt;&lt;b&gt;Logical XOR tests for different values: A xor B&lt;/b&gt;&lt;/caption&gt;
			    &lt;colgroup span="7"&gt;
		            &lt;col width="16%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		            &lt;col width="14%"&gt;
		        &lt;/colgroup&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;th&gt;&lt;/th&gt;&lt;th colspan="6"&gt;Value of B&lt;/th&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;th class="wid16pct"&gt;Value of A&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;1&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;'0.0'&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_true"&gt;&lt;font color="blue"&gt;a string&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;0&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;empty str&lt;/font&gt;&lt;/th&gt;
                    &lt;th class="wid14pct_false"&gt;&lt;font color="red"&gt;undef&lt;/font&gt;&lt;/th&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;1&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;'0.0'&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_true"&gt;&lt;font color="blue"&gt;&lt;b&gt;a string&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;0&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;empty str&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr align="center" class="center"&gt;
                    &lt;td class="bold_false"&gt;&lt;font color="red"&gt;&lt;b&gt;undef&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="istrue"&gt;&lt;font color="blue"&gt;true&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                    &lt;td class="isfalse"&gt;&lt;font color="red"&gt;false&lt;/font&gt;&lt;/td&gt;
                &lt;/tr&gt;
            &lt;/table&gt;

&lt;a name = "References" id = "References"&gt;&lt;/a&gt;
&lt;h3&gt;References&lt;/h3&gt;
    &lt;p&gt;
        &lt;ul&gt;
            &lt;li&gt;
                [doc://perldata]
            &lt;/li&gt;
            &lt;li&gt;
                [doc://perlsyn]
            &lt;/li&gt;
            &lt;li&gt;
                [doc://perlop]
            &lt;/li&gt;
            &lt;li&gt;
                [id://133554]
            &lt;/li&gt;
            &lt;li&gt;
                [id://862]
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/p&gt;

&lt;p&gt;
    Thanks to [tye], [castaway], [GrandFather], and [Detonite] for their pre-post comments.
&lt;/p&gt;

&lt;p&gt;
    &lt;strong&gt;Updates:&lt;/strong&gt;
    &lt;ul&gt;
        &lt;li&gt;
            Changed the AND and OR tables to more clearly show which value is returned, per [Skeeve]'s suggestion.
        &lt;/li&gt;
        &lt;li&gt;
            Minor rewording to make it more clear that the rules are quoted directly from the Perl docs, per Anonymous Monk's comments.
        &lt;/li&gt;
    &lt;/ul&gt;
&lt;/p&gt;
</field>
</data>
</node>
