A common mistake is to write:
unlink $file || die "snafu";
This gets interpreted as:
unlink ($file || die "snafu");
To avoid this problem, either put in extra parentheses or use the super low
precedence or
operator:
(unlink $file) || die "snafu"; unlink $file or die "snafu";
The ``English'' operators (and
, or
, xor
, and not
) deliberately have precedence lower than that of list operators for just
such situations as the one above.
Another operator with surprising precedence is exponentiation. It binds
more tightly even than unary minus, making -2**2
product a negative not a positive four. It is also right-associating,
meaning that 2**3**2
is two raised to the ninth power, not eight squared.