Perl哈希:$ hash {key}与$ hash-> {key}

固体

Perl newb在这里,对一个愚蠢的问题感到抱歉,但是->在编码上下文中使用谷歌搜索是很困难的……有时,我将这样访问一个哈希值:$hash{key}有时不起作用,所以我会这样访问它$hash->{key}这里发生了什么?为什么有时它以一种方式而不是另一种方式起作用?

帖木儿

区别在于,在第一种情况下%hash是哈希,在第二种情况下$hash是对哈希的引用(=哈希引用),因此您需要使用不同的符号。在第二种情况下,->取消引用$hash

例子:

# %hash is a hash:
my %hash = ( key1 => 'val1', key2 => 'val2');

# Print 'val1' (hash value for key 'key1'):
print $hash{key1}; 

# $hash_ref is a reference to a hash:
my $hash_ref = \%hash;

# Print 'val1' (hash value for key 'key1', where the hash 
# in pointed to by the reference $hash_ref):
print $hashref->{key1}; 

# A copy of %hash, made using dereferencing:
my %hash2 = %{$hash_ref}

# $hash_ref is an anonymous hash (no need for %hash).
# Note the { curly braces } :
my $hash_ref = { key1 => 'val1', key2 => 'val2' };

# Access the value of anonymous hash similarly to the above $hash_ref:
# Print 'val1':
print $hashref->{key1};

也可以看看:

perlreftut:https://perldoc.perl.org/perlreftut.html

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Ruby Combine Hash Key As Hash + Key and return as array

来自分类Dev

hash [key]是hash.fetch(key),就像@ivar是什么?

来自分类Dev

为什么我们有双重哈希函数,如[[hash1(key)+ i * hash2(key))%TABLE_SIZE],而不仅仅是[[i * hash2(key))%TABLE_SIZE]?

来自分类Dev

Redis 多 Key 或多 Hash 字段

来自分类Dev

rspec存根以允许传递[hash_key]

来自分类Dev

Ruby将Hash Key作为Hash + Key组合并作为数组返回

来自分类Dev

Hash.fetch(not_exist_key)引发IndexError而不是KeyError

来自分类Dev

Ruby Hash类的方法has_key?vs方法成员?

来自分类Dev

适用于Facebook的Android Key Hash和Cordova

来自分类Dev

DBI :: st = HASH()-> _ prepare(...):属性参数不是哈希-Perl

来自分类Dev

Perl:不是HASH参考

来自分类Dev

hash()如何计算元组的哈希?

来自分类Dev

我的for hash哈希表错误

来自分类Dev

如何在Swift 4中复制hash_hmac('sha256',$ key,$ secret_key)函数?

来自分类Dev

Jmeter中的x-appiyo-key和x-appiyo-hash是什么?

来自分类Dev

使用Terraform更改hash_key导致表已存在错误

来自分类Dev

hash_hmac函数中的secret_key参数是什么

来自分类Dev

在HASH索引上使用PRIMARY KEY插入表的时间复杂度

来自分类Dev

如何在Firebase中的默认auth:export之后为auth:import设置hash-key选项?

来自分类Dev

等效于 .NET 中的 PHP hash_hmac("sha384", $data, $key)

来自分类Dev

How to correctly merge one hash into another, replacing the first key. RoR

来自分类Dev

具有多个值的Ruby Hash Key:及时返回最小值

来自分类Dev

如何在java中通过Hash和Range Key查询DynamoDB?

来自分类Dev

在Perl Hash中推送键/值对的列表

来自分类Dev

在Perl中有HASH参考问题

来自分类Dev

在 perl 中,为什么当哈希包含长字符串时 sprintf(Dumper \%hash) 会抛出警告?

来自分类Dev

HashMap中Key的“ Normalize”哈希

来自分类Java

使用Oracle STANDARD_HASH,在JAVA中重现哈希

来自分类Dev

PHP password_hash始终包含哈希键

Related 相关文章

  1. 1

    Ruby Combine Hash Key As Hash + Key and return as array

  2. 2

    hash [key]是hash.fetch(key),就像@ivar是什么?

  3. 3

    为什么我们有双重哈希函数,如[[hash1(key)+ i * hash2(key))%TABLE_SIZE],而不仅仅是[[i * hash2(key))%TABLE_SIZE]?

  4. 4

    Redis 多 Key 或多 Hash 字段

  5. 5

    rspec存根以允许传递[hash_key]

  6. 6

    Ruby将Hash Key作为Hash + Key组合并作为数组返回

  7. 7

    Hash.fetch(not_exist_key)引发IndexError而不是KeyError

  8. 8

    Ruby Hash类的方法has_key?vs方法成员?

  9. 9

    适用于Facebook的Android Key Hash和Cordova

  10. 10

    DBI :: st = HASH()-> _ prepare(...):属性参数不是哈希-Perl

  11. 11

    Perl:不是HASH参考

  12. 12

    hash()如何计算元组的哈希?

  13. 13

    我的for hash哈希表错误

  14. 14

    如何在Swift 4中复制hash_hmac('sha256',$ key,$ secret_key)函数?

  15. 15

    Jmeter中的x-appiyo-key和x-appiyo-hash是什么?

  16. 16

    使用Terraform更改hash_key导致表已存在错误

  17. 17

    hash_hmac函数中的secret_key参数是什么

  18. 18

    在HASH索引上使用PRIMARY KEY插入表的时间复杂度

  19. 19

    如何在Firebase中的默认auth:export之后为auth:import设置hash-key选项?

  20. 20

    等效于 .NET 中的 PHP hash_hmac("sha384", $data, $key)

  21. 21

    How to correctly merge one hash into another, replacing the first key. RoR

  22. 22

    具有多个值的Ruby Hash Key:及时返回最小值

  23. 23

    如何在java中通过Hash和Range Key查询DynamoDB?

  24. 24

    在Perl Hash中推送键/值对的列表

  25. 25

    在Perl中有HASH参考问题

  26. 26

    在 perl 中,为什么当哈希包含长字符串时 sprintf(Dumper \%hash) 会抛出警告?

  27. 27

    HashMap中Key的“ Normalize”哈希

  28. 28

    使用Oracle STANDARD_HASH,在JAVA中重现哈希

  29. 29

    PHP password_hash始终包含哈希键

热门标签

归档