On Wed, Dec 05, 2001 at 04:32:49AM -0500, Michael G Schwern wrote:
> On Wed, Dec 05, 2001 at 03:30:07AM +0100, Bart Lateur wrote:
> > 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?
> 
> At the risk of being prosaic:
> 
> sub is_false ($) { defined $_[0] && !$_[0] }

Looks like "~" doesn't trigger a warning on undef.

So
~$a ? $a ? 3 : 2 : 1

will yield 3 for true, 2 for false, 1 for undef.

-Sven
-- 
So I'm ugly.  So what?  I never saw anyone hit with his face.
                -- Yogi Berra

Reply via email to