Here's a random assortment from my Perl anomalies file. Seen any good
anomalies lately?
# the second is a semantic error.
(substr($x, 0, 1), substr($x, 3, 1)) = ('a', 'b');
# semantic error.
($a, local($b)) = (2, 3);
# semantic error.
substr($x = 'abc', 0, 1) = 'd';
substr(local($x) = 'abc', 0, 1) = 'd';
# the second doesn't do what you expect. a vector assignment
# in a scalar context returns the vector's length.
$x = 3; $y = 4; ++($x, $y); print $x, $y;
# prints nothing.
($a, $b) += (3, 4);
# only does $b += 4. $a is unchanged.
# does nothing.
$a = *b = 'z';
# sets $a to *z, rather than 'z'. the value of a scalar
# assignment is the lhs, not the rhs.
(1 ? $x : $y) = 5;
# semantic error.
$x ? $y = 3 : $z = 4;
# unlike C, this gets parsed as ($x ? $y = 3 : $z) = 4.
$x = (2, 3, 4,)[2];
# the second is a syntax error.
$_ = '12345'; print length > 3;
$_ = '12345'; print length < 3;
# the second doesn't do what you expect.
# compare: print length < 3;>
while () {}
until () {}
# the second is a syntax error.
while () {}
while (()) {}
while {} {}
1 while ();
# the first is an infinite loop, the other three are not.
$_ = 1; print exp $_ % -1;
$_ = 1; print exp % -1;
# the second doesn't do what you expect.
# compare: print exp % ;