Quick Tip #22: Use Perl 5 modules in Perl 6

Perl 6 has always had a goal of interacting with other languages. When Larry Wall announced the project in 2000, he talked about translate with 95-percent accuracy 95 percent of the scripts. He wanted a way to run Perl 5 from Perl 6.

And, with Inline::Perl5, you can do that. Most notably, you can load Perl 5 modules:

use v6;
use Inline::Perl5;
use Business::ISBN:from<Perl5>;

my $isbn = Business::ISBN.new( '9781491954324' );

say $isbn.as_isbn10.as_string;

In the authority section of the module, I specified from<Perl5>. To make this work, you need to compile perl as specified in the Inline::Perl5 README.md. You need a perl compiled with -Duseshrplib; I had to compile a new perl but that wasn’t a big deal.

If you are using a recent Rakudo and you’ve already installed Inline::Perl5, that module loads implicitly:

use v6;
use Business::ISBN:from<Perl5>;

my $isbn = Business::ISBN.new( '9781491954324' );

say $isbn.as_isbn10.as_string;

Leave a Reply

Your email address will not be published. Required fields are marked *