相关疑难解决方法(0)

如何使用“使用严格”导入常量,避免“不能使用裸字......作为数组引用”

我在一个文件中有一个模块,它导出一个作为数组引用的常量。我可以在其定义模块中使用该常量,但在导入后无法使用它。错误消息说Can't use bareword ("AR") as an ARRAY ref while "strict refs" in use at mod.pl line 28.

考虑这个演示代码:

#!/usr/bin/perl
require 5.018_000;

use warnings;
use strict;

package Test;

use warnings;
use strict;

BEGIN {
    require Exporter;
    our $VERSION = 1.00;                # for version checking
    # Inherit from Exporter to export functions and variables
    our @ISA = qw(Exporter);
    our @EXPORT = qw();                 # exported by default
    our @EXPORT_OK = qw(AR);            # can be optionally exported
}

use constant AR => …
Run Code Online (Sandbox Code Playgroud)

import perl module reference constants

4
推荐指数
1
解决办法
409
查看次数

标签 统计

constants ×1

import ×1

module ×1

perl ×1

reference ×1