【问题标题】:How can I pass a constant to a Perl subroutine?如何将常量传递给 Perl 子例程?
【发布时间】:2010-03-17 22:09:17
【问题描述】:

我得到如下:

 use constant ABC => ('one', 'two', 'three');

我想将此常量作为@data 传递给variations_with_repetition(\@data, $k) 子例程。

我该怎么做?

【问题讨论】:

  • 有什么理由不使用use constant ABC => ['one', 'two', 'three'];[ ABC ] 每次使用都会创建一个新的匿名数组。

标签: perl reference constants subroutine


【解决方案1】:

使用 [] 运算符将列表转换为 ARRAY 引用:

variations_with_repetition( [ABC] , $k );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-02-01
    • 2012-05-30
    • 1970-01-01
    • 2012-05-18
    • 1970-01-01
    • 2021-08-12
    • 2011-02-22
    • 2016-11-22
    相关资源
    最近更新 更多