2013-03-06 33 views

回答

3
use Encode; 

my $byte1 = "C3"; 
my $byte2 = "A9"; 
my $bytes = chr(hex($byte1)) . chr(hex($byte2)); 
print decode_utf8($bytes); 
+0

此答案完美工作!我很感謝幫助。 ikegami的答案幫助我瞭解了十六進制值發生了什麼。 – iohans 2013-03-06 10:09:17

1

啊哈YSTH打我:字符串文字的

#!/usr/bin/env perl 

use strict; 
use warnings; 

use Encode; 
use utf8::all; 

my $byte1 = "C3"; 
my $byte2 = "A9"; 
my $bytes = join '', map {chr hex} $byte1, $byte2; 

print decode_utf8($bytes); 
+0

感謝您的答案。這也是有效的。 – iohans 2013-03-06 10:10:07

3

覺得作爲一個小型的語言。你不能這樣做

"\x$hex" 

任何比你更可以做

my $for = 'for'; 
$for (1..4) { } 

但也有很多方法可以做你想做的。

my $bytes = join '', map chr hex, @bytes_hex; 
my $bytes = pack 'C*', map hex, @bytes_hex; 
my $bytes = pack '(H*)*', @bytes_hex; 
+0

感謝您的解釋。 「\ xCA」部分讓我認爲這是一個字符串,因爲0xCA沒有被引用。 – iohans 2013-03-06 10:11:22

相關問題