问题描述
以下 Perl 5 脚本:
使用严格;使用警告;使用数据::打印机;我的@a = (1,2,3,4);p@a;
给出输出:
(注意蓝色),而这个 Perl 6 脚本:
use Data::Printer:from;我的@a = 1,2,3,4;p@a;
给出输出:
[[0] 1,[1] 2,[2] 3、[3] 4]但数字没有着色(如上面的 Perl 5 案例).
系统信息:
$ perl --version这是为 x86_64-linux 构建的 perl 5, version 29, subversion 3 (v5.29.3)$ perl6 -e '.say for $*DISTRO, $*VM, $*PERL.compiler.version'ubuntu (18.10.Cosmic.Cuttlefish)摩尔 (2018.11)v2018.11
这似乎是 Data::Printer 的 >version 0.40,这是 metacpan 上的当前版本.如果我从 GitHub 安装 0.99 版,我也会使用 Perl 6 获得颜色.另请参阅此问题.
我稍微调试了 0.40 版,似乎从 Perl 5 版本调用 p @a
与从 Perl 6 调用相同的调用之间的唯一区别是 Perl 6 调用在列表上下文中调用,因此 wantarray
返回 truePerl 6 调用,这显然使 Data::Printer
以某种方式关闭着色.
The following Perl 5 script:
use strict;
use warnings;
use Data::Printer;
my @a = (1,2,3,4);
p @a;
gives output:
(note the blue color), whereas this Perl 6 scripts:
use Data::Printer:from<Perl5>;
my @a = 1,2,3,4;
p @a;
gives output:
[
[0] 1,
[1] 2,
[2] 3,
[3] 4
]
but the numbers are not colored (as for the Perl 5 case above).
System information:
$ perl --version
This is perl 5, version 29, subversion 3 (v5.29.3) built for x86_64-linux
$ perl6 -e '.say for $*DISTRO, $*VM, $*PERL.compiler.version'
ubuntu (18.10.Cosmic.Cuttlefish)
moar (2018.11)
v2018.11
This seems to be an issue with version 0.40 of Data::Printer
which is the current version on metacpan. If I install version 0.99 from GitHub I get colors with Perl 6 also. See also this issue.
I debugged version 0.40 a little bit, and it seems like the only difference between the call to p @a
from Perl 5 version versus the same call from Perl 6, is that the Perl 6 call is called in list context, so wantarray
returns true for the Perl 6 call, this apparantly makes Data::Printer
turn off coloring somehow.
这篇关于终端 ANSI 颜色不适用于 Inline::Perl5 (Data::Printer)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!