perl中Windows-1252到unicode的转换

perl中Windows-1252到unicode的转换,perl,unicode,Perl,Unicode,我有十六进制格式的Windows-1251字符。 该值为0xF4。我想用perl转换和打印字符。 我可以通过unicode 0x0444来实现。 我正在寻找一种将0xF4转换为0x044的方法。 我的最终计划是在任何编码中给定任何字符的十六进制值,我应该能够将其转换为unicode的十六进制值,并最终能够打印它。 但它不起作用 下面是我正在使用的代码 #!/usr/bin/perl use strict; use utf8; use Encode qw(decode encode); binm

我有十六进制格式的Windows-1251字符。 该值为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

ô

输出是正确的–在CP-1252中,
0xF4
确实是
ô
()

您想指定它


谢谢阿蒙,这很有帮助。让我分享一下我为什么需要这个。我试图解析一个rtf文件,其内容是ф&在vi中,它如下所示。rtf提到了unicode cpg1252。RTF::TEXT::Converter无法工作,因此使用RTF::Tokenizer{\rtf1\ansi\ansicpg1252\fromtext\fbidis\deff0{\FONTBL{\f0\fswiss\fcharset0 Arial;}{\f1\fmodern Courier New;}{\f2\fnil\fcharset2 Symbol;}{\f3\fmodern\fcharset0 Courier New;}{\f4\fswiss\fcharset204;}{\COLORDTBL\FREEN0\green0\BLUEN255\FREEN0;}\uc1\pard\plain\deftab360\f0\fs20\htmlrtf{\f4\fs20\htmlrtf0\f4\htmlrtf\f0}\htmlrtf0\par}
use Encode 'decode';
my $cp1251 = "\xF4";
my $decoded = decode "cp1251", $cp1251;
print "$decoded\n";