合并哈希 (Raku)

Merge Hash (Raku)

常见问题解答,Int Raku,如何合并,合并两个哈希值?

说:

my %a = 1 => 2;
my %b = 3 => 4, 5 => 6

如何获得%c = 1 => 2, 3 => 4, 5 => 6

  1. 使用Slip prefix |
  2. 使用append哈希方法
  3. 使用infix , operator

假设:

my %a = 1 => 'a', 3 => 4;
my %b = 1 => 'b', 5 => 6;
say %(|%a, |%b);  # {1 => b, 3 => 4, 5 => 6}
say %().append(%a).append(%b);  # {1 => [a b], 3 => 4, 5 => 6}
my %c = %a, %b; say(%c);  # {1 => b, 3 => 4, 5 => 6}