> On 26 Sep 2015, at 13:09, Aristotle Pagaltzis <[email protected]> wrote:
> * Moritz Lenz <[email protected]> [2015-09-26 09:40]:
>> A trailing comma helps:
>>
>> my %h = a => 1, b => 2;
>> my @a = %h, ;
>> say @a.perl; # [{:a(1), :b(2)},]
>
> I think I understand why, but wow, that’s not reasonable. Is there
> really no better way to avoid the flattening? Even Perl 5 is nicer
> in that situation…
There is: you just need to itemize the hash, e.g. by prefixing it with $
$ 6 'my %h = a => 42, b => 666; my @a = $%h; dd @a'
Array @a = [{:a(42), :b(666)},]
This is the one argument rule at work.
The flattening will not be done if more than one argument is specified:
$ 6 'my %h = a => 42, b => 666; my @a = %h,%h; dd @a'
Array @a = [{:a(42), :b(666)}, {:a(42), :b(666)}]
This is the same behaviour as with for:
$ 6 'my %h = a => 42, b => 666; dd $_ for %h'
:a(42)
:b(666)
$ 6 'my %h = a => 42, b => 666; dd $_ for %h,%h'
Hash %h = {:a(42), :b(666)}
Hash %h = {:a(42), :b(666)}
It’s the same rule throughout :-)
Liz