在使用data :: dumper PERL打印时,不会遵守口音
我想打印出关联数组的内容。
为此,我使用了Data :: dumper。
I would like to print out the content of an associative array. For this I'm using Data::dumper.
例如,如果关联数组被称为%w,我写: / p>
So, for exemple, if the associative array is called "%w", I write :
print OUT Dumper(\%w);
问题出在这里:有一些单词如récente被打印为r \ x {e9} cente。
Here's the problem: there are some words like "récente" that are printed out as "r\x{e9}cente".
如果我只写:
If I write just :
print OUT %w;
我没有任何问题,所以récente将打印为récente。
I've no problems, so "récente" it will be printed out as "récente".
脚本使用的所有文本文件都在utf8中。
此外,我使用模块utf8,并且我总是指定字符编码系统。
All text files used for the script are in utf8. Moreover I use the module "utf8" and I specify always the character encoding system.
例如, :
open( IN, '<', $file_in);
binmode(IN,":utf8");
我很确定问题与Data :: dumper有关。有没有办法解决这个或另一种方式来打印出关联数组的内容?
I'm pretty sure that the problem is related to Data::dumper. Is there a way to solve this or another way to print out the content of an associative array?
谢谢。
这是故意的。当 eval
被用作Perl代码时, Data :: Dumper
的输出用于产生相同的数据结构。为了限制字符编码的效果,非ASCII字符将被转义使用转义。除此之外,设置 $ Data :: Dumper :: Useqq = 1
是明智的,这样任何不可打印的字符都可以使用转义符转储。
This is intentional. The output by Data::Dumper
is intended to produce the same data structure when eval
uated as Perl code. To limit the effect of character encodings, non-ASCII characters will be dumped using escapes. In addition to that, it's sensible to set $Data::Dumper::Useqq = 1
so that any unprintable characters are dumped using escapes.
Data :: Dumper
并不是真正意义上的显示数据结构的方式 - 如果您有特定的格式要求,只需自己编写必要的代码即可。例如
Data::Dumper
isn't really meant as a way to display data structures – if you have specific formatting requirements, just write the necessary code yourself. For example
use utf8;
use feature 'say';
open my $out, ">:utf8", $filename or die "Can't open $filename: $!";
my %hash = (
bárewørdş => '–Uni·code–',
);
say { $out } "{";
for my $key (sort keys %hash) {
say { $out } " $key: $hash{$key}";
}
say { $out } "}";
产生
{
bárewørdş: –Uni·code–
}