On Wed, Dec 05, 2001 at 10:43:14AM +0100, Sven Neuhaus wrote:
> 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.

So, to answer your question,

~$a && !$a
will only be true for false.

-Sven
-- 
La-dee-dee, la-dee-dah.

Reply via email to