我一直试图将Perl5模块Data::Printer
加载到Perl6中,但遇到了困难。
我早些时候Cannot import Perl5 module using Inline::Perl5 into Perl6问过这个问题,确实从@raiph和伊丽莎白那里得到了有用的建议,但被建议再做一个问题
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脚本中。
答案 0 :(得分:7)
p5_to_p6中不受支持的NativeCall :: Types :: Pointer <94859011731840>
这是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