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?