如何在 Perl 管道上设置编码?
“打开我的 $column, '|-:encoding(utf-8)', qw(column);”中的“'|-:encoding(utf-8)'”是好的?看起来差不多了。在带有“Mikołaj”的行中,格式不正确;我该如何修复它?
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
binmode STDOUT, ':encoding(utf-8)';
# edit:
binmode DATA, ':encoding(utf-8)';
open my $column, '|-:encoding(utf-8)', qw(column);
print $column "$_\n" for <DATA>;
__DATA__
Julius
Giovanni
George
Alonso
Jerome
Eugène
Reinhold
Gustav
Pavel
Franz
Max
Mikołaj
Maurice
Alec
Émile
Xaver
Henry
Wolfgang
Alexander
Enrico
Bedrich
Joaquín
Bartholomäus
Otto
Carl
Isaak
Anatol
Leos
Herbert
Paul
Benjamin
Matthew
Jean
Is "'|-:encoding(utf-8)'" in "open my $column, '|-:encoding(utf-8)', qw(column);" ok? It seems to work almost. In the row with the "Mikołaj" the formatting is not correct; how can I fix it?
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
binmode STDOUT, ':encoding(utf-8)';
# edit:
binmode DATA, ':encoding(utf-8)';
open my $column, '|-:encoding(utf-8)', qw(column);
print $column "$_\n" for <DATA>;
__DATA__
Julius
Giovanni
George
Alonso
Jerome
Eugène
Reinhold
Gustav
Pavel
Franz
Max
Mikołaj
Maurice
Alec
Émile
Xaver
Henry
Wolfgang
Alexander
Enrico
Bedrich
Joaquín
Bartholomäus
Otto
Carl
Isaak
Anatol
Leos
Herbert
Paul
Benjamin
Matthew
Jean
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您谈到格式化,显然想要对齐输出。我注意到 ł 是示例中唯一没有出现在 Latin1 中的字符。要排除您使用的字体很愚蠢的问题,请配置您的终端以显示具有广泛覆盖范围的良好字体: DejaVu Sans Mono 很好。
另外,你已经对输出进行了十六进制转储了吗?这就是我得到的:
You talk about formatting and evidently want aligned output. I notice that ł is the only character in the sample not occurring in Latin1. To rule out the problem that you just have a stupid font, configure your terminal to display a well-behaved one with extensive coverage: DejaVu Sans Mono is nice.
Also, have you hexdumped the output yet? This is what I get:
这个示例脚本在 BSD/OSX 中对我来说可以正常工作。通常,当格式出现问题时,可能是某个地方的编码不匹配。确保:
This example script works correctly for me in BSD/OSX. Usually when there's an issue with formatting it's an encoding mismatch somewhere. Make sure: