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

Re: tri-state flags

Thread Previous | Thread Next
From:
Lars Henrik Mathiesen
Date:
December 5, 2001 08:26
Subject:
Re: tri-state flags
Message ID:
20011205162516.8047.qmail@tyr.diku.dk
bernie@fantasyfarm.com ("Bernie Cosell") writes:
>On 5 Dec 2001, at 11:34, abigail@foad.org wrote:
>> But Bart said he wanted to test for 0. The test above, and several of
>> the other proposals don't distinguish between 0 and the empty string.

Here's a trick: ~(~$flag||0) will map the false values undef and ''
into 4294967295 (as well as the string "Ï"). It will pass both numeric
0 and "0" through, however.

>Well, what I thought he actually said was that the flag had one of
>the values 1,0,undef.

In that case, ! ~(~$flag||0) is what he needs.

>I suppose you could then consider it a quinary flag with two other
>hidden/illegal values: true but not 1, and false but not-numeric-zero
>and so in the '0' have to actually test for "was it really ZERO"
>rather than the flas- but-not-numeric-zero case.

The test above will yield false for '' and true for "0".

>but from what he said, I'd think that bumming off of concluding "It
>is not undef and not true" implies "it must have been zero" is legit
>within the parameters of the challenge, no??

That must be for Bart to decide.

Lars Mathiesen (U of Copenhagen CS Dep) <thorinn@diku.dk> (Humour NOT marked)

Thread Previous | 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