如何在 Perl6 中加载 Perl5 的 Data::Printer? [英] how to load Perl5's Data::Printer in Perl6?

查看:36
本文介绍了如何在 Perl6 中加载 Perl5 的 Data::Printer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我之前问过这个问题,无法使用内联导入 Perl5 模块:Perl5 转换为 Perl6 并确实从 @raiph 和 Elizabeth 那里得到了有用的建议,但被建议做另一个问题

con@con-VirtualBox:~$ perldoc -lm Data::Printer/usr/local/share/perl/5.26.0/Data/Printer.pmcon@con-VirtualBox:~$ perl6退出类型 'exit' 或 '^D'>使用内联::Perl5;零>使用 lib:from<Perl5>'/usr/local/share/perl/5.26.0/Data/';零>我的@a = 1,2,3,4[1 2 3 4]>p@a===抱歉!=== 编译时出错:未声明的例程:p 在第 1 行使用

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

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

<代码>>使用 Data::Printer:from<Perl5>不支持的类型 NativeCall::Types::Pointer<94859011731840>在 p5_to_p6 中在/usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 298 的方法 p5_to_p6_type 中在/usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 375 的方法 unpack_return_values 中在/usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 446 的方法调用中在/usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 776 的方法导入中在/usr/lib/perl6/site/sources/130449F27E85303EEC9A19017246A5ED249F99E4 (Inline::Perl5) line 805 的 sub EXPORT 中在/usr/lib/nqp/lib/Perl6/Grammar.moarvm 第 1 行的任何 statement_control 中

我不知道如何有效地将该库加载到 Perl6 脚本中.

解决方案

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

这是 Inline::Perl 中的一个错误 4 天前修正.

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

#安装一个位置无关版本的perl,# 见 https://github.com/niner/Inline-Perl5/$ perlbrew install perl-5.29.7 --as perl-5.29.7-PIC -Duseshrplib -Dusemultiplicity$ perlbrew install-cpanm$ perlbrew 使用 perl-5.29.7-PIC$ cpanm 数据::打印机$ git clone https://github.com/niner/Inline-Perl5.git$ cd Inline-Perl5/# 如果您已经安装了它,请先运行:'zef uninstall Inline::Perl5'$ perl6 configure.pl6$ make$ make install # 这将安装最新版本的 Inline::Perl5$ cd ..

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

use Data::Printer:from;我的@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 卸载内联::Perl5$ zef 安装.# 或者创建上面的`Makefile`

I've been trying to load in the Perl5 module Data::Printer into Perl6, but am having a hard time.

I asked this earlier, Cannot import Perl5 module using Inline::Perl5 into Perl6 and did get useful advice from @raiph and Elizabeth, but was advised to do another question

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

The p routine should be loaded, and yet it isn't.

alternatively, I try to load, but this produces a bug as well

> 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

I have no idea how I can usefully load this library into a Perl6 script.

解决方案

Unsupported type NativeCall::Types::Pointer<94859011731840> in p5_to_p6

This was a bug in Inline::Perl that was fixed 4 days ago.

You will not get this lastest version if you simply do zef install Inline::Perl5. Here is what I did:

# 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 ..

Then I tested this with this script (p.p6):

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

Running perl6 p.p6 gives now:

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

Edit: If you already have installed a position independent perl binary, the above installation procedure can be simplified:

$ 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 

这篇关于如何在 Perl6 中加载 Perl5 的 Data::Printer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆