How is an 'array' of 'hashes' made in Perl 6?

8

I want to create an 'array' of 'hashes' in Perl 6. For example:

use Test;
plan 1;

my @esperado = [ 
                {A => 1, B => 2}; 
                {C => 3, D => 4}; 
            ];

my %hash1 = A => 1, B => 2;
my %hash2 = C => 3, D => 4;

my @resultado;

@resultado.push( %hash1, );   # o @resultado.push( [%hash1], )
@resultado.push( %hash2, );   # o @resultado.push( [ %( C => 3, D => 4)], );

is-deeply @resultado, @esperado, 'crear array de hashes';

This results in the following:

1..1
not ok 1 - crear array de hashes

# Failed test 'crear array de hashes'
# at test.p6 line 17
# expected: [{:A(1), :B(2)}, {:C(3), :D(4)}]
#      got: [:B(2), :A(1), :D(4), :C(3)]
# Looks like you failed 1 test of 1

In Perl 5, a reference to a hash can be used as an element of an array. Is there something similar in Perl 6?

    
asked by Christopher Bottoms 06.01.2016 в 18:24
source

1 answer

5

With the latest version of Rakudo (2015.12-117), I get a correct result:

1..1
ok 1 - crear array de hashes

The explanation of the references is in link

    
answered by 07.01.2016 / 07:24
source