Front page | perl.fwp |
Postings from December 2001
Re: tri-state flags
Thread Previous
|
Thread Next
From:
Sven Neuhaus
Date:
December 5, 2001 02:36
Subject:
Re: tri-state flags
Message ID:
20011205113559.E15635@neopoly.com
On Wed, Dec 05, 2001 at 04:56:34AM -0500, Michael G Schwern wrote:
> On Wed, Dec 05, 2001 at 10:43:14AM +0100, Sven Neuhaus wrote:
> > 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.
>
> That's no good, repetition of the expression is a no-no.
>
> Note that "$flag" may well be an expression, so repetition as in
> the next, is not good:
>
> defined $flag && !$flag
Granted, you have to put it in a function:
sub is_false { ~$_[0] && !$_[0] }
This could still be a problem for tied variables.
Anyway, I think it's interesting to see that '~' is the same as 'defined'
(for boolean evaluation). Should be handy for golfing.
-Sven
--
Money is the root of all wealth.
Thread Previous
|
Thread Next