Conditional XOR operations
I was working on an iRule that only needed an OR if I didn’t reverse the logic on of them. But when I looked at the original problem, it needed one condition or the other but not both. You can nest conditionals to accomplish this, but I wanted an XOR operator, and Tcl doesn't have one at the string level, only with bitwise operations. So here is what that looks like in a truth table, where A could be an IP address range, B could be a hostname, and Q would be the truth condition.
A | B | Q |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
In an iRule, this would look like this structurally (but you would need to add your comparisons for each A/B variable to whatever makes them true:
if { ($a || $b) && !($a && $b) } {
# act on the XOR true condition
} else { # act on the XOR false condition }
Published Oct 15, 2024
Version 1.0JRahm
Admin
Joined January 20, 2005
No CommentsBe the first to comment