作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我读过在为哈希定义键值时使用宽逗号,我们不需要在键周围放置 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/
我是一名优秀的程序员,十分优秀!