gpt4 book ai didi

带胖逗号的 perl 散列

转载 作者:行者123 更新时间:2023-12-01 04:44:03 25 4
gpt4 key购买 nike

我读过在为哈希定义键值时使用宽逗号,我们不需要在键周围放置 quotes '' 来指示它是一个字符串。但是,我发现如果我在键周围包含 quotes,它仍然可以正常工作,就好像它忽略了 '' 一样。

下面的声明可以安全使用吗?

$result = { 
'Bill' => { Java => 56, C => 78, Perl => 90 } ,
'Mary' => { Java => 82, C => 65, Perl => PX, Python => 72},
};

最佳答案

在使用粗逗号时,您不需要使用单引号,如果您愿意,可以可以。它是可选的。

胖逗号只是一个逗号,唯一的区别是如果存在一个裸词,一个没有引号的词,那么它将把这个裸词当作单引号。

来自 perlop :

The => operator is a synonym for the comma except that it causes a word on its left to be interpreted as a string if it begins with a letter or underscore and is composed only of letters, digits and underscores. This includes operands that might otherwise be interpreted as operators, constants, single number v-strings or function calls. If in doubt about this behavior, the left operand can be quoted explicitly.

关于带胖逗号的 perl 散列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24103294/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com