【问题标题】:Scalar found where operator expected when I try to copy a hash from another module当我尝试从另一个模块复制哈希时,标量找到了运算符的预期位置
【发布时间】:2013-10-19 22:04:21
【问题描述】:
Scalar found where operator expected at /pgfs1/eng/hchian2/bin/soc/fc_net_tracer.pl line 158, near "%hash_build_db::$cblock"
        (Missing operator before $cblock?)
syntax error at /pgfs1/eng/hchian2/bin/soc/fc_net_tracer.pl line 158, near "%hash_build_db::$cblock"
Execution of /pgfs1/eng/hchian2/bin/soc/fc_net_tracer.pl aborted due to compilation errors.

我正在尝试从另一个模块复制哈希,但这个问题错误阻止了我。

我用来引用我在hash_build_db.pm 中创建的哈希的代码是

use hash_build_db;
%$cblock = %hash_build_db::$cblock;

【问题讨论】:

    标签: perl hash


    【解决方案1】:

    应该是这样的

    %$cblock = %hash_build_db::cblock;
    

    如果你在hash_build_db 包中有cblock 哈希,并且$cblock 是哈希引用。

    【讨论】:

    • %$cblock 是否必须使用严格的 %{$cblock}?
    • @AlexTape 不,这两件事的意思是一样的,不管严格与否。
    • @AlexTape %$cblock%{ $cblock } 的短版,单独的解引用不受strict 的影响
    • 啊好吧..我阻止这样做是因为使用警告和诊断..即使出现警告;)
    猜你喜欢
    • 2015-11-20
    • 1970-01-01
    • 2012-06-16
    • 2013-01-10
    • 1970-01-01
    • 2021-12-27
    • 2019-02-02
    • 2023-04-03
    • 2014-11-25
    相关资源
    最近更新 更多