本文介绍了警告 - “散列分配中的奇数元素"在 perl 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下语法收到警告 -

I am getting the warning with use of following syntax -

my %data_variables = ("Sno." => (5,0),
                "ID" => (20,1), 
                "DBA" => (50,2), 
                "Address" => (80,3), 
                "Certificate" => (170,4),
            );

但是我在使用类似的语法时没有收到类似的警告.

But I dont get a similar warning at use of similar syntax.

my %patterns = ("ID" => ("(A[0-9]{6}?)"),
                "Address" => (">([^<]*<br[^>]+>[^<]*)<br[^>]+>Phone"),
                "Phone" => ("Phone: ([^<]*)<"),
                "Certificate" => ("(Certificate [^\r\n]*)"),
                "DBA" => ("<br[^>]+>DBA: ([^<]*)<br[^>]+>"),
            );  

推荐答案

您需要将括号更改为方括号:

You need to change your parentheses to square brackets:

my %data_variables = (
    "Sno."        => [5,0],
    "ID"          => [20,1], 
    "DBA"         => [50,2], 
    "Address"     => [80,3], 
    "Certificate" => [170,4],
);

哈希值必须是标量值,因此您的数字列表需要存储为数组引用(因此使用方括号).

Hash values must be scalar values, so your lists of numbers need to be stored as array references (hence the square brackets).

在您的第二个示例中,括号是多余的,只会混淆问题.每组括号只包含一个标量值(一个字符串),每个标量值都成为一个哈希值.

In your second example, the parentheses are superfluous and just confuse the matter. Each set of parentheses contains just one scalar value (a string), each of which becomes a hash value.

这篇关于警告 - “散列分配中的奇数元素"在 perl 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 08:38