【问题标题】:perl error: no 'new' method in 'Statistics::Descriptive"perl 错误:“Statistics::Descriptive”中没有“新”方法
【发布时间】:2011-02-23 08:50:51
【问题描述】:

我使用 cpan 安装了“Statistics::Descriptive”模块,然后测试示例:

use Statistics::Descriptive;
$stat = new Statistics::Descriptive;
$stat->AddData(1,2,3,4);

但它显示错误:Can't locate object method "new" via package "Statistics::Descriptive" at ... 我在 Linux Ubuntu 中使用 Perl 版本 5.10.1 和 cpan 告诉我的最新 Statistics::Descriptive 执行此操作。

我在 windows 上使用 activestate perl 进行了尝试,它可以工作。

您知道为什么我在 Linux 中运行时出现此错误吗?谢谢。

【问题讨论】:

    标签: perl perl-module


    【解决方案1】:

    documentation 看来您需要做任何一个

    use Statistics::Descriptive;
    my $stat = Statistics::Descriptive::Full->new();
    

    use Statistics::Descriptive;
    my $stat = Statistics::Descriptive::Sparse->new();
    

    正如所说:“使用稀疏方法,不存储任何数据,只有少数统计度量可用。使用完整方法,保留整个数据集并提供其他功能。”

    也许你在 Windows 上有一个旧版本。旧版本有一个 undocumented 顶级 new() 方法。

    【讨论】:

    • 谢谢你。似乎这行代码是通过使用my $stat = Statistics::Descriptive::Full->new();Sparse 传递的。但是,似乎在包中找不到对象方法并显示:Can't locate object method "AddData" via package "Statistics::Descriptive::Sparse" at ...。你有什么主意吗?谢谢。
    • @Kenneth:我认为你的意思是 add_data; AddData 真的可以在 Windows 上运行吗?即使仍然在 cpan 上的非常旧的版本也没有 AddData。
    • Windows 上的代码示例适用于此代码示例:use Statistics::Descriptive;$stat = new Statistics::Descriptive;$stat->AddData(1,2,3,4);$mean = $stat->Mean();$var = $stat->Variance();$tm = $stat->TrimmedMean(.25);,如 Statistics::Descriptive 下载页面。那么你有什么好的例子可以让我效仿吗?谢谢你。
    • @Kenneth:只是我在答案开头链接到的文档中的示例;不知道你说的下载页面是什么意思。
    • 糟糕...抱歉,我没有注意链接。好的..我知道我的问题是什么。我正在阅读旧版 Statistics::Descriptive 的下载页面。现在一切正常。非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-05
    • 2023-03-29
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多