How can I combine hashes in Perl?

后端 未结 4 938
天命终不由人
天命终不由人 2020-11-29 00:29

What is the best way to combine both hashes into %hash1? I always know that %hash2 and %hash1 always have unique keys. I would also prefer a single line of code if possibl

4条回答
  •  伪装坚强ぢ
    2020-11-29 00:56

    For hash references. You should use curly braces like the following:

    $hash_ref1 = {%$hash_ref1, %$hash_ref2};
    

    and not the suggested answer above using parenthesis:

    $hash_ref1 = ($hash_ref1, $hash_ref2);
    

提交回复
热议问题