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];
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
On Sat, Sep 26, 2015 at 10:37 AM, Moritz Lenz wrote:
> Hi,
>
> This works:
> my @b; @b.push: $%h;
> say @b.perl;# [{:a(1), :b(2)},]
>
> Cheers,
> Moritz
>
Thanks. it worked.
I kept throwing various sigils, bracket, and commas around in hope of
getting this work without
any success
* Moritz Lenz [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…
-
> On 26 Sep 2015, at 13:09, Aristotle Pagaltzis wrote:
> * Moritz Lenz [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 w
* Elizabeth Mattijsen [2015-09-26 13:20]:
> 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,
Itemization helps:
m: my %h = x => 6, y => 7; my @a = $%h; say @a[0]
rakudo-moar 0132b6: OUTPUT«x => 6, y => 7»
m: my %h = x => 6, y => 7; my @a; @a.push: $%h; say @a[0]
rakudo-moar 0132b6: OUTPUT«x => 6, y => 7»
Am 26.09.2015 um 07:58 schrieb Gabor Szabo:
> In the first two cases the hash was
On 09/26/2015 02:26 PM, Aristotle Pagaltzis wrote:
> Now of course I must ask – is there an opposite also? I.e. when writing
> a list, is there a way I can say “do flatten this item?”
Yes, that's what type Slip is for: http://doc.perl6.org/type/Slip
It's useful for returning more than one list
> On 26 Sep 2015, at 14:26, Aristotle Pagaltzis wrote:
> * Elizabeth Mattijsen [2015-09-26 13:20]:
>> 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 argum