Hello Marshall,

0E0 is more often seen, but this works the same way.

Yes, but only when it appears as a string; when it appears as a number, it is zero and false:

#! perl use strict; use warnings; for ( 0, 0E0, '0E0', 0.0, '0.0', 0.00, '0.00', 00, '00', '0', '0 but true', '0 BUT TRUE', '0 but true ', '1 and true', ) { printf "%-11s %d %s\n", $_, ($_ + 0), ($_ ? 'true' : 'false'); }

Output:

13:25 >perl 1575_SoPW.pl 0 0 false 0 0 false 0E0 0 true 0 0 false 0.0 0 true 0 0 false 0.00 0 true 0 0 false 00 0 true 0 0 false 0 but true 0 true Argument "0 BUT TRUE" isn't numeric in addition (+) at 1575_SoPW.pl li +ne 34. 0 BUT TRUE 0 true Argument "0 but true " isn't numeric in addition (+) at 1575_SoPW.pl l +ine 34. 0 but true 0 true Argument "1 and true" isn't numeric in addition (+) at 1575_SoPW.pl li +ne 34. 1 and true 1 true 13:25 >

The string '0' is documented as special: it is zero and false. Other strings are true1 regardless of their numerical values. It appears that the isn't numeric warning applies only when the numerical conversion is not “pure” (because the string contains non-numeric characters).

It seems strange that this behaviour is so poorly documented. The '0 but true' special case is not mentioned in perlsyn#Truth-and-Falsehood. My experiments suggest that this special string must be character-for-character exact for the special behaviour to apply. For example, '0 but true ' (note the extra space at the end) still generates an isn't numeric warning.

Update: 1Except the empty string, '', which is also documented to be false.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re^3: The True but Zero value? by Athanasius
in thread The True but Zero value? by Marshall

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.