a = 0011
b = 1010
a = a ^ b (a now contains 1001)
b = a ^ b (b now contains 0011 - a's original contents)
a = a ^ b (a now contains 1010 - b's original contents)
In the example code two strings get swapped using the technique. However if the strings are different lengths then the shorter string will end up with trailing null characters. The substitution strips the nulls. A tr could have been used instead, but substitutions are more often used in general so a better thing for the OP to be made aware of.
DWIM is Perl's answer to Gödel
|