So we all know the COMPSCI 101 method of swapping two variables:

$tmp = $x; $x = $y; $y = $tmp;

And we all know the better way of doing it:

($x, $y) = ($y, $x);

And yet, I found the following in PRODUCTION CODE, that a contractor was PAID ACTUAL DOLLARS TO WRITE:

($tmp_x, $tmp_y) = ($x, $y);

($x, $y) = ($tmp_y, $tmp_x);

Weird that they knew about parallel assignment but not that you could just apply it to two variables directly.

Anyhow, this wasn’t nearly as bad as the code I found in a different module (same vendor) to swap all the 1s and 0s in a string. Now this is a somewhat less trivial problem than simply swapping two variables, but

$str =~ tr/01/10/;

does the job nicely. Alas, in the same vein as the variable-swap, the method that vendor went with was:

$str =~ s/0/2/g;

$str =~ s/1/3/g;

$str =~ s/2/1/g;

$str =~ s/3/0/g;

Good thing

$str

doesn’t contain any

2

s or

3

s!