【问题标题】:how to load Perl5's Data::Printer in Perl6?如何在 Perl6 中加载 Perl5 的 Data::Printer?
【发布时间】:2019-06-29 18:49:17
【问题描述】:

我一直在尝试将 Perl5 模块 Data::Printer 加载到 Perl6 中,但遇到了困难。

我之前问过这个问题,Cannot import Perl5 module using Inline::Perl5 into Perl6,确实从@raiph 和 Elizabeth 那里得到了有用的建议,但被建议做另一个问题

con@con-VirtualBox:~$ perldoc -lm Data::Printer
/usr/local/share/perl/5.26.0/Data/Printer.pm
con@con-VirtualBox:~$ perl6
To exit type 'exit' or '^D'
> use Inline::Perl5;
Nil
> use lib:from<Perl5> '/usr/local/share/perl/5.26.0/Data/';
Nil
> my @a = 1,2,3,4
[1 2 3 4]
> p @a
===SORRY!=== Error while compiling:
Undeclared routine:
    p used at line 1

p 例程应该被加载,但它没有。

或者,我尝试加载,但这也会产生错误

> use Data::Printer:from<Perl5>
Unsupported type NativeCall::Types::Pointer<94859011731840> in p5_to_p6
  in method p5_to_p6_type at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 298
  in method unpack_return_values at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 375
  in method invoke at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 446
  in method import at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 776
  in sub EXPORT at /usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 805
  in any statement_control at /usr/lib/nqp/lib/Perl6/Grammar.moarvm line 1

我不知道如何有效地将这个库加载到 Perl6 脚本中。

【问题讨论】:

  • 你不应该只使用use Data::Printer:from&lt;Perl5&gt;吗?您不必使用use lib:from&lt;Perl5&gt; '/usr/local/share/perl/5.26.0/Data/' 设置包含路径,并且您缺少use Data::Printer:from&lt;Perl5&gt; 语句,请参阅the GitHub page for Inline::Perl5 示例。
  • @HåkonHægland 我已经编辑了问题以显示给出的错误
  • 这似乎和你之前的问题一样,see the answer by Elizabeth
  • @HåkonHægland 那里的解决方案是不可接受的。伊丽莎白可能是正确的,这是语言或模块深处的错误,但另一位用户建议可能有更好的修复
  • 你好@con。 Håkon 现在添加了一个非常简单的 4 行配方来刷新您的 IP5。如果您已经安装了git,您可能会发现您只需键入这 4 行,当他们完成他们的工作后,您就可以全部设置好了。如果您没有安装了git,那么您需要先安装。如果您决定尝试,请告诉我们。如果你这样做了,那么原则上(模数错误就像你发现的那样)你应该能够安装 P5 模块,然后编写 use ... :from&lt;Perl5&gt; 行,然后编写 P6 代码来使用 P5 功能。所以这对你来说可能是 P6 实用程序的一大改进。

标签: raku


【解决方案1】:

p5_to_p6 中不支持的类型 NativeCall::Types::Pointer

这是Inline::Perl that was fixed 4 days ago 中的一个错误。

如果您只是执行zef install Inline::Perl5,您将无法获得最新版本。 这是我所做的:

# Install a position independent version of perl, 
#   see  https://github.com/niner/Inline-Perl5/
$ perlbrew install perl-5.29.7 --as perl-5.29.7-PIC -Duseshrplib -Dusemultiplicity
$ perlbrew install-cpanm
$ perlbrew use perl-5.29.7-PIC
$ cpanm Data::Printer
$ git clone https://github.com/niner/Inline-Perl5.git
$ cd Inline-Perl5/
# Run: 'zef uninstall Inline::Perl5' first if you already have it installed
$ perl6 configure.pl6
$ make
$ make install # this installs the latest version of Inline::Perl5
$ cd ..

然后我用这个脚本(p.p6)对此进行了测试:

use Data::Printer:from<Perl5>;
my @a = 1,2,3,4;
p @a;

运行 perl6 p.p6 现在给出:

[
    [0] 1,
    [1] 2,
    [2] 3,
    [3] 4
]

编辑:如果你已经安装了一个独立于位置的perl二进制,上面的安装过程可以简化:

$ git clone https://github.com/niner/Inline-Perl5.git
$ cd Inline-Perl5/
$ zef uninstall Inline::Perl5
$ zef install . # or alternatively create the `Makefile` as above 

【讨论】:

  • 感谢 cmets @raiph!我认为你是对的,有更简单的方法可以做到这一点。我认为包含有关使用perlbrew 安装独立于位置的perl 的说明可能会有所帮助,但这可能会令人困惑。如果您在我的回答中已经拥有独立于职位的perl,我将包含更简单的方法。
  • 这是一个了不起的工作@HåkonHægland 唯一的缺点是颜色没有通过,但这是非常小的。非常感谢和感谢!
  • 嗨@raiph。是的,你是对的,颜色在 P6 中不起作用。我有posted an SO question。感谢您对此进行调查!
猜你喜欢
  • 1970-01-01
  • 2019-07-03
  • 2019-06-26
  • 1970-01-01
  • 1970-01-01
  • 2018-09-11
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多