我一直在尝试将Perl5模块加载Data::Printer到Perl6中,但是我很难过.
我之前问过这个问题,不能使用Inline :: Perl5将Perl5模块导入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
Run Code Online (Sandbox Code Playgroud)
该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
Run Code Online (Sandbox Code Playgroud)
我不知道如何将这个库有用地加载到Perl6脚本中.
p5_to_p6中不支持的类型NativeCall :: Types :: Pointer <94859011731840>
这是Inline::Perl 4天前修复的错误.
如果你愿意,你不会得到这个最新的版本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 ..
Run Code Online (Sandbox Code Playgroud)
然后我用这个脚本测试了这个(p.p6):
use Data::Printer:from<Perl5>;
my @a = 1,2,3,4;
p @a;
Run Code Online (Sandbox Code Playgroud)
跑步perl6 p.p6现在给出:
[
[0] 1,
[1] 2,
[2] 3,
[3] 4
]
Run Code Online (Sandbox Code Playgroud)
编辑:如果您已经安装了与位置无关的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
Run Code Online (Sandbox Code Playgroud)