Jun 3, 2004 #1 Nebbish Programmer Joined Apr 7, 2004 Messages 73 Location US An easy one: what's the syntax for an exclusive or? I need: if($true XOR $false) to pass but not: if($true XOR $true) to pass. Thanks, Nick
An easy one: what's the syntax for an exclusive or? I need: if($true XOR $false) to pass but not: if($true XOR $true) to pass. Thanks, Nick
Jun 3, 2004 1 #2 toolkit Programmer Joined Aug 5, 2001 Messages 771 Location GB This works: Code: $a = 1; $b = 0; if ($a xor $b) { print "Hello World\n"; } Cheers, Neil Upvote 0 Downvote
Jun 3, 2004 Thread starter #3 Nebbish Programmer Joined Apr 7, 2004 Messages 73 Location US Heh, I guess I should have tried the obvious first, eh? Is that the typical syntax, or is there a syntax similar to || and &&? Thanks, Nick Upvote 0 Downvote
Heh, I guess I should have tried the obvious first, eh? Is that the typical syntax, or is there a syntax similar to || and &&? Thanks, Nick
Jun 3, 2004 #4 toolkit Programmer Joined Aug 5, 2001 Messages 771 Location GB See here for a full explanation of the operators and precedence: http://www.perldoc.com/perl5.6/pod/perlop.html Code: printf "%d\n", 4 ^ 3; ## bitwise XOR (100 ^ 011 = 111) if(4 xor 3) { print "true\n"; } else { print "false\n"; ## 4 is true, 3 is true, hence true XOR true is false } There is no high precedence logical XOR operator, ie: Code: operation high low ------------------------- 'and' && and 'or' || or 'xor' -none- xor Cheers, Neil Upvote 0 Downvote
See here for a full explanation of the operators and precedence: http://www.perldoc.com/perl5.6/pod/perlop.html Code: printf "%d\n", 4 ^ 3; ## bitwise XOR (100 ^ 011 = 111) if(4 xor 3) { print "true\n"; } else { print "false\n"; ## 4 is true, 3 is true, hence true XOR true is false } There is no high precedence logical XOR operator, ie: Code: operation high low ------------------------- 'and' && and 'or' || or 'xor' -none- xor Cheers, Neil
Jun 3, 2004 Thread starter #5 Nebbish Programmer Joined Apr 7, 2004 Messages 73 Location US I didn't realize there was a difference between 'and' and '&&'. Thanks for the posts. -Nick Upvote 0 Downvote