Scott,

I don't believe that you'll be able to shorten:
if($a){$a=0;do_something()}
any further unless you're able to use the flip-flop instead of $a:
if($|--){do_something()}

All suggestions so far have been longer.

hth
ty

> -----Original Message-----
> From: Scott Wiersdorf [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, 23 May 2002 05:05
> To: [EMAIL PROTECTED]
> Subject: shortest test for truth & false assignment
> 
> 
> Hello fwp'ers,
> 
> Here's a golfish problem that I thought some people might enjoy:
> 
> What is the shortest way to test a variable for truth and then set its
> value to false such that the truth test still succeeds?
> 
> For example, I have a global variable $a (given) that is somehow set
> to true. I want to test it for truth and do something:
> 
>     <snip>
>     $a = 1;
>     
>     ...
>     
>     if( $a ) {
>       $a = 0;
>       do_something();
>     }
> 
>     ## and now $a is false
>     ...
>     </snip>
> 
> You can't do this:
> 
>     if( $a = $a ? 0 : $a ) {
>         do_something();
>         ...
>     }
> 
> because the whole expression becomes false when $a is assigned 0.
> 
> My shortest try is this (10 characters w/o whitespace):
> 
>     if( $a%2 .. $a-- ) {
>         do_something();
>         ...
>     }
> 
> Assuming warnings and stricture, can anyone find a shorter
> test/assignment? It doesn't have to be numeric (i.e., bit strings or
> any true/false values will work).
> 
> Good luck!
> 
> Scott
> -- 
> Scott Wiersdorf
> [EMAIL PROTECTED]
> 

Reply via email to