Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

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.

like image 953
GeneQ Avatar asked Feb 07 '12 08:02

GeneQ


People also ask

Why was Perl 6 renamed Raku?

Since backward compatibility is a common goal when enhancing software, the breaking changes in Perl 6 had to be stated explicitly. The distinction between Perl 5 and Perl 6 became so large that eventually Perl 6 was renamed Raku.

How do Perl modules work?

The perl1 compiler (yes, there is a compiler although it's interpreted language) loads files, compiles them, then switches to run time to run the compiled code. When it encounters a new file to load, it switches back to compile time, compiles the new code, and so on. To load a module at compile time, you use it.

What is CPAN module in Perl?

The Comprehensive Perl Archive Network (CPAN) is a repository of over 250,000 software modules and accompanying documentation for 39,000 distributions, written in the Perl programming language by over 12,000 contributors.


1 Answers

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.

like image 122
user7610 Avatar answered Oct 01 '22 19:10

user7610