Tinmarino
Tinmarino

Reputation: 4061

Merge Hash (Raku)

FAQ, Int Raku, how to merge, combine two hashes?

Say:

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

How to get %c = 1 => 2, 3 => 4, 5 => 6 ?

Upvotes: 7

Views: 331

Answers (1)

Tinmarino
Tinmarino

Reputation: 4061

  1. Use Slip prefix |
  2. Use append Hash method
  3. Use infix , operator

Assuming:

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}

Upvotes: 6

Related Questions