in reply to Flip Flop IV

Well, Perl doesn't have any keywords for TRUE and FALSE.

Since TRUE and FALSE are barewords in your code, I assume that they are subroutine calls.

Otherwise, they would be caught with use strict (which everyone uses, right?). That is (remembering that use constant defines subroutines),

use constant FALSE => 0; use constant TRUE => !FALSE;

Assuming that they return 1 and 0 (or 0 and 1, it doesn't matter), then this would work:

Just use the xor operator:

my $debug = FALSE; # or 0 $debug ^= 1; # now it's TRUE, or 1 $debug ^= 1; # now it's FALSE, or 0

or use this:

$debug = !$debug; # change 1 to 0 or 0 to 1

update: added !, explanation/assumption at top.

Replies are listed 'Best First'.
Re: Re: Flip Flop IV
by grinder (Bishop) on Jun 25, 2001 at 16:58 UTC

    It's funny. I have been coding in one language or another since the early 80s, and it was only this year that I encountered Yet Another Way to write a flip-flop.

    my $ff = 0; while( 1 ) { print $ff ? 'hee ' : 'haw ', "\n"; $ff = 1 - $ff; }

    For some perverse reason this really appeals to me, although I refrain from using it in production code. It has a certain mathematical elegance.


    --
    g r i n d e r