例如,我有一个 string "\x80\x81\x82.abc\x00"
,那么它应该转换为 hex 8081822e61626300
。请问如何在Perl中做到这一点?
问问题
299 次
2 回答
3
你有字符串 吗"\x80\x81\x82.abc\x00"
? '\x80\x81\x82.abc\x00'
选项1:
my $text = "\x80\x81\x82.abc\x00";
$text = unpack "H*", $text;
print $text;
选项 2:
my $text = '\x80\x81\x82.abc\x00';
$text =~ s/\\x([a-zA-Z\d]{2})/{chr hex $1}/ge;
$text = unpack "H*", $text;
print $text;
于 2012-07-04T12:40:05.267 回答
0
unpack 'H*'
is likely the best solution:
$ perlsh
eval: unpack "H*", "\x80\x81\x82.abc\x00"
'8081822e61626300'
于 2012-07-04T09:59:33.793 回答