【发布时间】:2014-03-11 10:41:10
【问题描述】:
我有 Windows-1251 十六进制格式的 ef(cyrillic) 字符。 值为 0xF4。我想在 perl 中转换和打印字符。 我可以通过 unicode 0x0444 做到这一点。 我正在寻找一种将 0xF4 转换为 0x044 的方法。 我的最终计划是任何编码的任何字符的十六进制值,我应该能够将其转换为 unicode 的十六进制值并最终能够打印它。 但它不工作 以下是我正在使用的代码
#!/usr/bin/perl
use strict;
use utf8;
use Encode qw(decode encode);
binmode(STDOUT, ":utf8");
my $runtime = chr(0x0444);
print "theta || ".$runtime." ||";
my $smiley = "\x{0444}";
print "theta || ".$smiley." ||";
my $georgian_an = pack("U", 0x0444);
print "theta || ".$georgian_an." ||";
my $hexstr = "0xF4";
my $num = hex $hexstr;
print $num; # printing the hex value
my $be_num = pack("N", $num);
$runtime = decode( "cp1252",$be_num);
print "\n".$runtime."\n"; # i should have got ф here
输出
perl mychar_new.pl
theta || ф ||theta || ф ||theta || ф ||244
ô
【问题讨论】: