Import a simple module
I have a function written in a module ( .pm
) file and want to use it in a Perl6 ( .pl6
) file . These two files are in the same folder:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\perlCode
I tried using Perl6's answer : Implicit and Explicit Import , but my code returned this error:
===SORRY!=== Could not find chrmodule1 at line 5 in:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\modules
C:\Users\Christian\.perl6
C:\rakudo\share\perl6\site
C:\rakudo\share\perl6\vendor
C:\rakudo\share\perl6
CompUnit::Repository::AbsolutePath<84241584>
CompUnit::Repository::NQP<86530680>
CompUnit::Repository::Perl5<86530720> [Finished in 0.436s]
Here is the file .pm
, chrmodule1.pm
:
module chrmodule1 {
sub foo is export(:DEFAULT, :one) {
say 'in foo';
}
}
Here is the file .pl6
, testOfCode3.pl6
:
use v6;
use lib 'modules';
use chrmodule1;
foo();
- I am using this editor: atom.io
- Here's another solution to the problem that returned the same error when I tried it: perl6maven.com/tutorial/perl6-modules-export
-
Desired output:
in foo [Finished in 0.317s]
source to share
The second line testOfCode3.pl6
should be use lib 'perlCode';
.
You wrote:
I have a function written in a module (
.pm
) file and you want to use it in a Perl6 (.pl6
) file . These two files are in the same folder:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\perlCode
So you've saved the module in a folder named perlCode
.
When you run testOfCode3.pl6
you will get an error:
===SORRY!=== Could not find chrmodule1 at line 5 in:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\modules
So the Rakudo Perl 6 compiler was looking chrmodule
in a folder named modules
. What for? Because you told him:
Here is the file
.pl6
,testOfCode3.pl6
:
use v6;
use lib 'modules';
Operator A use lib ...
tells the Perl 6 compiler where to look for modules first. You added modules
, so the Rakudo Perl 6 compiler looked into the folder first modules
.
It didn't find your module there, so it continued looking elsewhere . Hence the lines listing C:\Users\Christian\.perl6
, etc.
After all, it never finds your module, because your module is in perlCode
and you didn't tell the compiler to look there. (And he refuses to just look in the current directory for security reasons.)
source to share