Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: Boolean counter?

by doug (Pilgrim)
on Dec 07, 2009 at 18:22 UTC ( #811589=note: print w/ replies, xml ) Need Help??

in reply to Re: Boolean counter?
in thread Boolean counter?

I agree that the XOR solution is perfectly correct, but why use that instead of NOT? Isn't

 $counter = ! $counter;

easier to read? That said, I have to admit that I like the snazzyness of the in place ^= syntax. It is hard to get more concise than that.

- doug

Comment on Re^2: Boolean counter?
Download Code
Replies are listed 'Best First'.
Re^3: Boolean counter?
by ikegami (Pope) on Dec 07, 2009 at 18:37 UTC

    The difference is that $toggle ^= 1; leaves you with a number (0 or 1) while $toggle = !$toggle; leaves you with a boolean.

    Honestly, it sounds like the OP wants a boolean, so the easier to read negation should be used. If he wants to display the boolean, that's an outputting formatting issue to be resolved then.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://811589]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (12)
As of 2015-11-25 20:33 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (690 votes), past polls