';包装';Perl中的函数

';包装';Perl中的函数,perl,pack,unpack,Perl,Pack,Unpack,我的Perl程序: say 'Hexadecimal notation in a Perl script'; my$str = pack 'H*', '987456123'; print unpack('H*', $str), "\n"; print unpack('h*', $str), "\n"; Hexadecimal notation in a Perl script 1. 9874561230 # Why is it showing zero here? 2. 8947652103

我的Perl程序:

say 'Hexadecimal notation in a Perl script';
my$str = pack 'H*', '987456123';
print unpack('H*', $str), "\n";
print unpack('h*', $str), "\n";
Hexadecimal notation in a Perl script
1. 9874561230 # Why is it showing zero here?
2. 8947652103
输出:

say 'Hexadecimal notation in a Perl script';
my$str = pack 'H*', '987456123';
print unpack('H*', $str), "\n";
print unpack('h*', $str), "\n";
Hexadecimal notation in a Perl script
1. 9874561230 # Why is it showing zero here?
2. 8947652103

在我的
1
结果中,为什么显示为零?这是什么原因?

您在
987456123
中有奇数个字符,
H*
打包要求偶数,因此最后一对字符为零(
98
74
56
12
30

发件人:

从模板的开头到pack(),每对字符将转换为输出的1个字符。[...] 如果输入字符串的长度不是偶数,则其行为就像在结尾处填充了空字符一样。类似地,“额外”Nybles在解包过程中被忽略


谢谢你澄清我的疑问有时我们使用
H*
,有时使用
*H
。我们为什么这样使用。与这些有什么区别?请告诉我know@OlegG, ""