我有两个哈希值,一个大一个小。所有较小哈希的键都显示在较大的哈希中,但值不同。我想将值从较大的哈希复制到较小的哈希。
例如:
# I have two hashes like so
%big_hash = (A => '1', B => '2', C => '3', D => '4', E => '5');
%small_hash = (A => '0', B => '0', C => '0');
# I want small_hash to get the values of big_hash like this
%small_hash = (A => '1', B => '2', C => '3');
一个明显的答案是遍历小散列的键,并像这样复制值
foreach $key (keys %small_hash) { $small_hash{$key} = $big_hash{$key}; }
有没有更短的方法来做到这一点?