开发者

perl how to use pack\unpack

开发者 https://www.devze.com 2023-01-26 12:42 出处:网络
I want to put in variable one byte in binary represantation of \'\\x01\' value. How can I do it in perl (I guess I should use开发者_开发百科 pack procedure)You don’t need pack for that.

I want to put in variable one byte in binary represantation of '\x01' value.

How can I do it in perl (I guess I should use开发者_开发百科 pack procedure)


You don’t need pack for that.

print "\x01";


#!/usr/bin/perl

use strict; use warnings;
my $x = 1;
my $y = 0x01;
my $z = hex '01';

print chr for $x, $y, $z;

Output:

C:\Temp> t | xxd
0000000: 0101 01                                  ...

Or,

printf '%02X' for $x, $y, $z;

depending on what you are actually trying to do.


pack("C", "\x01");


Thank you. I've already sorted it out.

What I was need is

my $post = pack("H1", '\x01');
0

精彩评论

暂无评论...
验证码 换一张
取 消