我有一个用模块文件(.pm
)编写的函数,并希望在Perl6文件(.pl6
)中使用它。这两个文件位于同一个文件夹中:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\perlCode
我尝试使用Perl6: implicit and explicit import的答案,但我的代码返回了此错误:
===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]
以下是.pm
文件,chrmodule1.pm
:
module chrmodule1 {
sub foo is export(:DEFAULT, :one) {
say 'in foo';
}
}
以下是.pl6
文件,testOfCode3.pl6
:
use v6;
use lib 'modules';
use chrmodule1;
foo();
期望的结果是:
in foo [Finished in 0.317s]
答案 0 :(得分:5)
testOfCode3.pl6
的第二行应为use lib 'perlCode';
。
您写道:
我有一个用模块文件(
.pm
)编写的函数,并希望在Perl6文件(.pl6
)中使用它。这两个文件位于同一个文件夹中:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\perlCode
因此,您已将模块存储在名为perlCode
的文件夹中。
当您运行testOfCode3.pl6
时,您会收到错误消息:
===SORRY!=== Could not find chrmodule1 at line 5 in:
C:\Users\Christian\Dropbox\ChristianPrivatefiler\Programmering\Perl6\modules
因此,Rakudo Perl 6编译器在名为chrmodule
的文件夹中查找modules
。为什么?因为你告诉它:
以下是
.pl6
文件,testOfCode3.pl6
:
use v6;
use lib 'modules';
use lib ...
语句告诉Perl 6编译器首先查找模块的位置。您已添加modules
,因此Rakudo Perl 6编译器首先查看modules
文件夹。
它没有在那里找到你的模块所以它继续,看elsewhere。因此列出C:\Users\Christian\.perl6
等的行
最后它永远找不到你的模块,因为你的模块在perlCode
,而你没有告诉编译器看那里。 (并且出于安全原因,它拒绝仅查看当前目录。)