Funny about the minus sign
作者:gugod 發佈於: ,更新於: #perl #operatorI just discovered that there something funny about this minus sign. See if you can guess the output of the following code without running it:
use strict;
use 5.010;
$, = " ";
for my $v (qw(42 FortyTwo)) {
say -$v, -"$v", -("$v");
say -(-($v)) , -(-$v), -(-$v);
say -(-("$v")) , -(-"$v"), -(-$v);
say -(-(-("$v"))) , -(-(-"$v")) , -(-(-$v));
}
It's pretty easy when the $v
is 42
, but not quite obvious when it is "FortyTwo"
. I don't have any explain on it. That's maybe documented somewhere and I'll have to find it.