2000-05-02-11:53:04 Jeff Pinyan: > On May 2, Bennett Todd said: > >which comes to 14 if I count right. Sure is a shame that there isn't > >a ^^ operator, which like && and || would treat its args as booleans > >rather than bitstrings. They could have done that when they > >introduced xor, but as best I can tell they didn't. > > Camel, ed. 2, pg. 94: > > There is also a logical B<xor> operator that has no exact counterpart in > C or Perl, since the other XOR operator (^) works on bits. The best > equivalent for C<$a xor $b> is perhaps C<!$a != !$b>[1]. This operator > can't short-circuit either, since both sides must be evaluated. Thanks for straightening me out, Jeff. I really thought I tested it out, but it looks like $_ xor!($_&$_-1) does in fact work, although, at 16 bytes, it's longer than my previous 14-byte (sense inverted) !$_^!($_&$_-1) which is in turn longer than Ilmari Karonen's wonderful little 11-byte: $_&$_-1|!$_ which is also simpler. So far I think Ilmari is the winner. -Bennett