用PERL处理二进制标量

您所在的位置:网站首页 perl二进制 用PERL处理二进制标量

用PERL处理二进制标量

2024-01-20 16:41| 来源: 网络整理| 查看: 265

I adopt select()...sysread()...syswrite() mechanism to handle socket messages, where messages are sysread() into $buffer (binary) before they are syswritten.

Now I want to change two bytes of the message, which denote the length of the whole message. At first, I use following code:

my $msglen=substr($buffer,0,2); # Get the first two bytesmy $declen=hex($msglen);$declen += 3;substr($buffer,0,2,$declen); # change the length

However, it doesn't work in this way. If the final value of $declen is 85, then the modified $buffer will be "0x35 0x35 0x00 0x02...". I insert digital number to $buffer but finally got ASCII!



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3