On Wed, 22 May 2002 13:04:53 -0600, Scott Wiersdorf wrote: >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(); > }
Shortest? Huh... I don't care, personally. But I sometimes do this, which has not too much redundancy (it only mentions $a once, for example): $a &&= do { do_something(); 0 }; $a will become 0 afterwards, the do BLOCK is only executed if $a was true. That was what you asked for, isn't it? -- Bart.