考虑这个简短的例子:
$a = pack("d",255);
print length($a)."\n";
# Prints 8
$aa = pack("ddddd", 255,123,0,45,123);
print length($aa)."\n";
# Prints 40
@unparray = unpack("d "x5, $aa);
print scalar(@unparray)."\n";
# Prints 5
print length($unparray[0])."\n"
# Prints 3
printf "%d\n", $unparray[0] '
# Prints 255
# As a one-liner:
# perl -e '$a = pack("d",255); print length($a)."\n"; $aa = pack("dd", 255,123,0,45,123); print length($aa)."\n"; @unparray = unpack("d "x5, $aa); print scalar(@unparray)."\n"; print length($unparray[0])."\n"; printf "%d\n", $unparray[0] '
现在,我希望双精度浮点数为 8 个字节,所以第一个length($a)
是正确的。但是为什么 unpack ( ) 报告 3 之后的长度length($unparray[0])
- 当我试图以完全相同的方式返回时(双精度,即 8 个字节) - 并且项目的值 (255) 被正确保留?