http://www.perlmonks.org?node_id=811449


in reply to Boolean counter?

You can just use ++ to increment your counter, but when you ask for its value use $counter % 2 instead of the counter itself.

Or if you're not interested in the numeric value 0, but rather that it's a false value, you can also use this update step:

$counter = !$counter;

Replies are listed 'Best First'.
Re^2: Boolean counter?
by JavaFan (Canon) on Dec 07, 2009 at 11:59 UTC
    Or if you do want the numerical value:
    $counter = !$counter || 0;