Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to include file in Raku

I have two Raku files:

hello.p6:

sub hello
{
    say 'hello';
}

and main.p6:

require 'hello.p6';

hello();

But don't work. How to can include the first file in the main script?

like image 420
Juan Manuel Avatar asked Nov 07 '12 03:11

Juan Manuel


2 Answers

Just for the record, the proper solution is to use a module:

File Hello.pm6

 module Hello;
 sub hello() is export {
     say 'hello';
 }

File hello.p6:

 use v6;
 use lib '.'; # to search for Hello.pm6 in the current dir
 use Hello;
 hello;
like image 81
moritz Avatar answered Nov 11 '22 13:11

moritz


Using explicit file syntax and explicit export list seems to work for me in Rakudo:

main.p6:

require Hello:file('Hello.p6') <hello>;

hello();

hello.p6:

sub hello {
    say 'hello';
}

Source: http://perlcabal.org/syn/S11.html#Runtime_Importation

like image 5
mvp Avatar answered Nov 11 '22 15:11

mvp