【问题标题】:Perl CPAN module object method not found errorPerl CPAN 模块对象方法未找到错误
【发布时间】:2014-09-10 15:18:13
【问题描述】:

我正在尝试使用 CPAN 模块:Math::Vector::Real::Neighbors

我看到以下错误消息:

无法通过包“Math::Vector::Real”在 /usr/local/share/perl/5.14.2/Math/Vector/Real/Neighbors.pm 第 12 行找到对象方法“box”。

所以,我进入包裹看到了这个:my ($bottom, $top) = Math::Vector::Real->box(@_);

接下来,我进入Real.pm 包:/usr/local/share/perl/5.14.2/Math/Vector/Real.pm

我看到里面有box子例程:sub box {...

知道为什么会出现错误吗?

【问题讨论】:

  • 在您的脚本中在此之前发生了什么——您是否创建了 Math::Vector::Real 对象?
  • use strict; use warnings;之后添加use Math::Vector::Real;
  • @jm666 这回答了问题...我使用的是 synopsys 页面中的示例...我的错误...对不起
  • @jm666 你能把它贴出来让我接受吗
  • 我警告过外星人already posted 作为答案。

标签: perl cpan


【解决方案1】:

您需要在脚本顶部添加 use Math::Vector::Real 才能使 Math::Vector::Real::Neighbors 工作。以下代码按预期运行:

use strict;
use warnings;

use Math::Vector::Real;
use Math::Vector::Real::Neighbors;
use Math::Vector::Real::Random;

my @v = map Math::Vector::Real->random_normal(2), 0..1000;
my @nearest_ixs = Math::Vector::Real::Neighbors->neighbors(@v);

但请注意,如果没有 use Math::Vector::Real 行,它将无法工作。

【讨论】:

  • 注意:我已经向作者的 github repo 提交了一个拉取请求,以将其添加到文档中。
【解决方案2】:

我是 Perl 模块系列 Math::Vector::Real 的作者。

如今,为了找到一组点的邻居,Math::Vector::Real::kdTree 中提供的算法要好得多:

my @v = ...;
my $kdtree = Math::Vector::Real::kdTree->new(@v);
my @nearest_ixs = $kdtree->find_nearest_vector_all_internal;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-06
    • 2019-06-15
    • 2020-01-25
    • 1970-01-01
    • 2014-02-18
    • 2017-09-17
    • 1970-01-01
    • 2020-01-06
    相关资源
    最近更新 更多