in reply to Re^2: Determining whether a value is zero.
in thread Determining whether a value is zero.
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Determining whether a value is zero.
by JavaFan (Canon) on Mar 10, 2011 at 14:26 UTC |