develooper Front page | perl.fwp | Postings from December 2001

tri-state flags

Thread Next
Bart Lateur
December 5, 2001 00:03
tri-state flags
Message ID:
I often use tri-state flags, with possible value true (1), false (0), or
undetermined (undef).

The question is: how do you test for one of the flags, in particular for
0, without warnings?

For true, it's easy:


For undef, it's not hard:

	!defined $flag

But for 0?

Note that "$flag" may well be an expression, so repetition as in the
next, is not good:

	defined $flag && !$flag

So, who does better?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About