gpt4 book ai didi

perl - 哈希中的加号是什么意思?

转载 作者:行者123 更新时间:2023-12-04 00:11:22 31 4
gpt4 key购买 nike

我有以下 Perl 代码,但我不明白它在做什么。

use constant ANIMAL => 'rabbit'; 
if ($self->{+ANIMAL}) {
# Do something here
}
+有什么用常量前的符号 ANIMAL意思?

最佳答案

来自 perldoc constant :

You can get into trouble if you use constants in a context which automatically quotes barewords (as is true for any subroutine call). For example, you can't say $hash{CONSTANT} because CONSTANT will be interpreted as a string. Use $hash{CONSTANT()} or $hash{+CONSTANT} to prevent the bareword quoting mechanism from kicking in. Similarly, since the => operator quotes a bareword immediately to its left, you have to say CONSTANT() => 'value' (or simply use a comma in place of the big arrow) instead of CONSTANT => 'value'.

关于perl - 哈希中的加号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21173481/

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