Hi,
On 09/26/2015 07:58 AM, Gabor Szabo wrote:
> In the first two cases the hash was converted to Pairs before assigning
> to the array.
> Only the third case gave what I hoped for. How can I push a hash onto an
> array as a single entity?
>
>
> use v6;
>
> my %h = x => 6, y => 7;
> say %h.perl; # {:x(6), :y(7)}
>
> my @a = %h;
> say @a.elems; #
> say @a[0]; # x => 6
A trailing comma helps:
my %h = a => 1, b => 2;
my @a = %h, ;
say @a.perl; # [{:a(1), :b(2)},]
> my @c;
> @c.push(%h);
> say @c.elems; # 2
> say @c[0]; # x => 6
I would have expected the traiing comma to help here too:
my @b; @b.push: %h, ;
say @b.perl; # [:a(1), :b(2)]
but alas, not. I wonder if this is a bug.
This works:
my @b; @b.push: $%h;
say @b.perl; # [{:a(1), :b(2)},]
Cheers,
Moritz