简体   繁体   English

如何使用 Perl 6 中的 Perl 5 模块?

[英]How can I use Perl 5 modules from Perl 6?

Is the a way to use Perl 5 modules from CPAN from Rakudo Perl 6?是否可以从 Rakudo Perl 6 使用来自 CPAN 的 Perl 5 模块?

For example, how can I use the venerable Perl 5 module, CGI, which hasn't been ported yet, in Perl 6.例如,如何在 Perl 6 中使用尚未移植的古老的 Perl 5 模块 CGI。

Update:更新:

And what this funky code from some early Perl 6 module:来自一些早期 Perl 6 模块的时髦代码是什么:

use CGI:from<perl5>;

Is the :from<perl5> directive used to evoke some kind of a Perl 5 compatibility layer? :from<perl5>指令是否用于唤起某种 Perl 5 兼容层? Can't seem to find any documentation about it.似乎找不到任何关于它的文档。

Use Inline::Perl5 .使用Inline::Perl5


The following example shows how to use the CPAN hosted Perl 5 module Text::Unidecode ("the Unicode transliteration of last resort") in Raku.以下示例显示了如何在 Raku 中使用 CPAN 托管的 Perl 5 模块Text::Unidecode (“最后的 Unicode 音译”)。

First, install Inline::Perl5 if you don't already have it installed:首先,如果您还没有安装 Inline::Perl5,请安装它:

zef install Inline::Perl5

Now install the CPAN module if you don't already have it installed:如果你还没有安装 CPAN 模块,现在安装它:

perl -MCPAN -e "install Text::Unidecode"

You can now use the installed Perl module by writing a use statement with an appended :from<Perl5> (with an uppercase P , not :from<perl5> ) :您现在可以通过编写带有附加:from<Perl5> (带有大写P ,而不是:from<perl5> )的use语句来使用已安装的 Perl 模块:

use Text::Unidecode:from<Perl5>;
say Text::Unidecode::unidecode 'Solidarność';

displays:显示:

Solidarnosc

See also other SO posts about Inline::Perl5 .另请参阅有关 Inline::Perl5 的其​​他 SO 帖子

There is blizkost project that aims to use of perl5 code from Rakudo/Parrot.有一个blizkost项目旨在使用来自 Rakudo/Parrot 的 perl5 代码。 However it is AFAIK in quite early stage of development and probably not usable for real code.然而,它是 AFAIK,处于开发的早期阶段,可能无法用于实际代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM