I'm not adverse to a purely intellectual challenge.

But the specification of what is and what is not zero doesn't seem to comply with any either real-world or rational definition that I can think of. I cannot think of any existing implementation that would interprete "0" as zero, and not "00" or "0 ". Nor can I see any rational for doing so.

Without some logic as to why these arbitrary rules have been picked, you might as well do:

#! perl -slw use strict; use feature qw[ state ]; use Scalar::Util qw[ dualvar ]; my @true = ( 0, "0", 0.0, Scalar::Util::dualvar( 0, 1 ) ); my @false = ( 1, "foo", "00", "0 ", undef, "", Scalar::Util::dualvar( 1, 0 ), "0.0" ); sub isZero { state %isZero; unless( %isZero ) { $isZero{ $_ } = 1 for @true; $isZero{ $_ } = 0 for @false; } return $isZero{ $_ } if exists $isZero{ $_ }; die "Don't know"; } print "$_ : ", isZero( $_ ) for @true; print "$_ : ", isZero( $_ ) for @false;

As it can be infinitely extended to deal with any set of illogical rules.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: Determining whether a value is zero. by BrowserUk
in thread Determining whether a value is zero. by JavaFan

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.