<?xml version="1.0" encoding="windows-1252"?>
<node id="496035" title="Re: True or False? A Quick Reference Guide" created="2005-09-29 07:05:02" updated="2005-09-29 03:05:02">
<type id="11">
note</type>
<author id="961">
Anonymous Monk</author>
<data>
<field name="doctext">
&lt;em&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. (see perldata)&lt;/em&gt;
&lt;p&gt;
I know what you mean by the &lt;em&gt;null string&lt;/em&gt;, but not every one does, specially not the people who need a reference. Perl doesn't have the concept of &lt;em&gt;null&lt;/em&gt;, and we avoid using the term &lt;em&gt;null string&lt;/em&gt;, because it's not always clear what is meant by it, the &lt;em&gt;empty string&lt;/em&gt;, or an &lt;em&gt;undefined value&lt;/em&gt;. 
&lt;p&gt;
Having said that, you only list three things that are false in boolean context: the empty string (null string), the number 0, and the string "0". But you left out the most important one: the undefined value. But there are more, here's a (hopefully) complete list:
&lt;ul&gt;
&lt;li&gt;The undefined value.
&lt;li&gt;The number &lt;tt&gt;0&lt;/tt&gt;.
&lt;li&gt;The empty string.
&lt;li&gt;The string &lt;tt&gt;"0"&lt;/tt&gt;.
&lt;li&gt;An empty array.
&lt;li&gt;An empty hash.
&lt;li&gt;Objects with appropriate overloaded boolean value.
&lt;/ul&gt;
&lt;p&gt;&lt;em&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.
&lt;/em&gt;&lt;p&gt;
Well, there's also auto-vivification.
&lt;p&gt;&lt;em&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"). (see perlsyn)
&lt;/em&gt;&lt;p&gt;
I wonder why you mention &lt;tt&gt;while&lt;/tt&gt;, but not &lt;tt&gt;for(;;)&lt;/tt&gt; or &lt;tt&gt;until&lt;/tt&gt;. Having said that, your statement is close, but not completely true. The block can also be exited with a &lt;tt&gt;last&lt;/tt&gt;, &lt;tt&gt;return&lt;/tt&gt;, &lt;tt&gt;goto&lt;/tt&gt;, &lt;tt&gt;die&lt;/tt&gt; or even a &lt;tt&gt;next LABEL_TO_OUTER_BLOCK&lt;/tt&gt; statement. Furthermore, if the condition becomes false &lt;em&gt;during&lt;/em&gt; execution of the block, the execution isn't stopped - checks are only done before entering the block. Finally, there's
&lt;code&gt;
    do {
        ...
    } while (0);
&lt;/code&gt;
which will execute the block at least once, even if the condition is never true.</field>
<field name="root_node">
495975</field>
<field name="parent_node">
495975</field>
<field name="reputation">
38</field>
</data>
</node>
