perl how to use pack\unpack
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');
精彩评论