in reply to 0==undef, that's annoying. Is it?

Or:

ok( defined $score && $score==0, "score is 0", );

Or (because undef stringifies to the empty string) use string comparison:

cmp_ok( $score => eq => '0', "score is 0", );
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^2: 0==undef, that's annoying. Is it?
by mascip (Pilgrim) on Jul 15, 2012 at 22:41 UTC

    These work, but I don't like either of them (i'm being a bit too perfectionist there).

    The first one is not clear, it's a lot too complex to read, for such a simple assertion. The second one is exactly equivalent to my

    is($score, 0)
    assertion, but just harder to read.
    And i still prefer using cmp_ok() for numbers, as '==' indicates clearly that it's numbers. And
    is('1','1.0')
    returns 0, while
    cmp(1, '==', 1.0)
    is true.
    So... I'd like to use cmp_ok() for numbers, but i'll have to be careful to not compare zeros in there.

      Perhaps another alternative to consider is Test::NoWarnings.

      >perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; cmp_ok(0, '==', undef, 'is 0 really undefined?'); " ok 1 - is 0 really undefined? not ok 2 - no warnings # Failed test 'no warnings' # at C:/strawberry/5.14/perl/vendor/lib/Test/NoWarnings.pm line 38. # There were 1 warning(s) # (lots and lots of discussion about the warning elided) # 1..2 # Looks like you failed 1 test of 2.

      These work, but I don't like either of them (i'm being a bit too perfectionist there).

      :) No, not perfectionist, merely neurotic (overanxious) :) See, the language is what it is, learn its ways and go with the flow :) don't get annoyed at things outside of your control, control yourself :) serenity now