加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl Unicode:“宽字符串”错误

发布时间:2020-12-16 06:17:16 所属栏目:大数据 来源:网络整理
导读:我在 Windows 7上运行Active Perl 5.14. 我正在尝试编写一个程序,它将读入转换表,然后处理文件并用其他模式替换某些模式 – 以上所有的Unicode(UTF-8).这是该计划的开始: #!/usr/local/bin/perl# Load a conversion table from CONVTABLE to %ConvTable.# T
我在 Windows 7上运行Active Perl 5.14.
我正在尝试编写一个程序,它将读入转换表,然后处理文件并用其他模式替换某些模式 – 以上所有的Unicode(UTF-8).这是该计划的开始:

#!/usr/local/bin/perl
# Load a conversion table from CONVTABLE to %ConvTable.
# Then find matches in a file and convert them.
use strict;
use warnings;
use Encode;
use 5.014;
use utf8;
use autodie; 
use warnings    qw< FATAL  utf8     >;
use open        qw< :std  :utf8     >;
use charnames   qw< :full >;
use feature     qw< unicode_strings >;

my ($i,$j,$InputFile,$OutputFile,$word,$from,$to,$linetoprint);
my (@line,@lineout); 
my %ConvTable;    # Conversion hash
print 'Conversion table: opening file: E:My DocumentsPerlConversion table.txt'."n";
my $sta= open (CONVTABLE,"<:encoding(utf8)",'E:My DocumentsPerlConversion table.txt');
binmode STDOUT,':utf8';    # output should be in UTF-8
# Load conversion hash
while (<CONVTABLE>) {
    chomp;
    print "$_n"; # etc ...
# etc ...

事实证明,在这一点上,它说:

wide character in print at (eval 155)E:/Active Perl/lib/Perl5DB.pl:640]line 2,<CONVTABLE> line 1,etc...

这是为什么?我想我已经完成并实施了所有必要的处方,以正确处理Unicode字符串,解码和编码成UTF-8?
以及如何解决它?

TIA

海伦

解决方法

Perl调试器有自己的输出句柄,与STDOUT不同(尽管它可能最终与STDOUT位于同一位置).您还希望在脚本开头附近执行类似的操作:

binmode $DB::OUT,':utf8' if $DB::OUT;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读