How can I use Perl 5 modules from Perl 6?

亡梦爱人 提交于 2019-12-21 03:32:50

问题


Is the a way to use Perl 5 modules from CPAN from Rakudo Perl 6?

For example, how can I use the venerable Perl 5 module, CGI, which hasn't been ported yet, in Perl 6.

Update:

And what this funky code from some early Perl 6 module:

use CGI:from<perl5>;

Is the :from<perl5> directive used to evoke some kind of a Perl 5 compatibility layer? Can't seem to find any documentation about it.


回答1:


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

First, install Inline::Perl5 if you don't already have it installed:

zef install Inline::Perl5

Now install the CPAN module if you don't already have it installed:

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>) :

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

displays:

Solidarnosc

See also other SO posts about Inline::Perl5.




回答2:


There is blizkost project that aims to use of perl5 code from Rakudo/Parrot. However it is AFAIK in quite early stage of development and probably not usable for real code.



来源:https://stackoverflow.com/questions/9173043/how-can-i-use-perl-5-modules-from-perl-6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!