in reply to Hash value test of zero
If you want to roll your own then something like this should do. Feel free to expand @zero and @notzero as desired.
use strict; use warnings; use Test::More; my @zero = (0, 0.0, -0, -0.0, 0E0); my @notzero = (1, -1, 1.1, -1.1, '', undef, 'foo', 'a string', 3, 4, \ +@zero); plan tests => @zero + @notzero; for my $scalar (@zero) { ok is_zero ($scalar), "$scalar is zero"; } for my $scalar (@notzero) { ok !is_zero ($scalar), ($scalar // 'undef') . ' is not zero'; } sub is_zero { my $scalar = shift; return defined ($scalar) && length ($scalar) && (!$scalar || $scal +ar eq '0E0'); }
Personally, I would probably go with Scalar::Util::looks_like_number.
This occurs whether strict is called or not, and it also happens whether "my" is declared on the hash name or not, so keeping the samples simple and omitting that part...
It is generally a bad idea not to show the entirety of the code producing the problematic result. See SSCCE for more on this.
🦛
|
---|