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

tri-state flags

Thread Next
From:
Bart Lateur
Date:
December 5, 2001 00:03
Subject:
tri-state flags
Message ID:
9b1r0uonrb1qj51r0hfpdl63b1cslc4d8j@4ax.com
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:

	$flag

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?

-- 
	Bart.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About