K
kj
The if procedure Test:k is given 3 arguments, it evaluates the
first 2 arguments, tests to see if they are equal (using eq), and
prints a message involving the 3rd argument if they are not.
Supposing that we wanted a test that succeeded if foo() > 0, and
having the message upon failure contain the string "bad foo". One
could use something like ok(foo() > 0, 1, 'bad foo'), on the
assumption that if foo() > 0 was true it would evaluate to 1.
I remember reading somewhere that it was bad form to assume any
particular value for a truth value in Perl, because the implementation
reserved the right to change this value.
But I don't remember whether one could assume that whatever truth
value a Perl implementation used, it would be *consistent*. For
example, can one assume that the expression ((1 > 0) eq (1 > 0))
will always evaluate to true? Assuming that this is the case,
to code the test above one could write something like this
ok(foo() > 0, !!1, 'bad foo')
Are expressions such as !!1 and !1 (or !!2 and !3, etc.) the best
way in Perl to code true and false values in an implementation-independent
way?
Thanks,
kj
first 2 arguments, tests to see if they are equal (using eq), and
prints a message involving the 3rd argument if they are not.
Supposing that we wanted a test that succeeded if foo() > 0, and
having the message upon failure contain the string "bad foo". One
could use something like ok(foo() > 0, 1, 'bad foo'), on the
assumption that if foo() > 0 was true it would evaluate to 1.
I remember reading somewhere that it was bad form to assume any
particular value for a truth value in Perl, because the implementation
reserved the right to change this value.
But I don't remember whether one could assume that whatever truth
value a Perl implementation used, it would be *consistent*. For
example, can one assume that the expression ((1 > 0) eq (1 > 0))
will always evaluate to true? Assuming that this is the case,
to code the test above one could write something like this
ok(foo() > 0, !!1, 'bad foo')
Are expressions such as !!1 and !1 (or !!2 and !3, etc.) the best
way in Perl to code true and false values in an implementation-independent
way?
Thanks,
kj