gpt4 book ai didi

关于 "undefined subroutine"的 Perl 模块错误

转载 作者:行者123 更新时间:2023-12-04 13:14:30 29 4
gpt4 key购买 nike

我正在尝试使用一个名为 Math::Counting 的模块:

#!/usr/bin/perl 

use strict;
use warnings;
use Math::Counting;

my $f = factorial(3);
print "$f\n";

但是,当我运行它时,出现以下错误
$ perl UsingModules.pl
Undefined subroutine &main::factorial called at UsingModules.pl line 8.

好像函数 factorial没有被导出,但为什么呢?

当我使用以下
my $f = Math::Counting::factorial(3);

而不是上面的,它工作得很好,但我很好奇为什么不能导出这个函数。

我正在使用 perl Cygwin 上的 v5.10.1。

最佳答案

模块中存在错误。 Math::Counting ISA Exporter , 但是 Math::Counting不加载 Exporter .

解决方法:您可以 requireuse Exporter手动。

更好:向模块作者提交错误,提供测试用例。

评论:

哦,很有趣。模块作者确实测试了他的功能,但是 Test::More拉入Exporter ,这意味着没有注意到模块源中的这种遗漏。

更新:

Math::Counting 0.0904 已经发布,解决了这个问题。

关于关于 "undefined subroutine"的 Perl 模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10318313/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com