develooper Front page | perl.perl6.users | Postings from June 2017

Creating an array of a single hash

Thread Next
Gabor Szabo
June 1, 2017 14:29
Creating an array of a single hash
Message ID:
use v6;

my @x = { name => "Foo" }, { name => "Bar"}
say @x.gist;     # [{name => Foo} {name => Bar}]
say @x.^name;    # Array
say @x[0].^name; # Hash

my @y = { name => "Foo" }
say @y;           # [name => Foo]
say @y.^name;     # Array
say @y[0].^name;  # Pair

my @z = { name => "Foo" },;
say @z;           # [{name => Foo}]
say @z.^name;     # Array
say @z[0].^name;  #  Hash

In the first example, creating an array of 2 hashes work.
In the second example the listy assignment removes the hashy-ness of
the right hand side.
In the 3rd example adding a comma at the end solves the problem.

Is this how it is recommended to initiate an array with a single hash?
Is there an operator that forces the assignment to item-assignment?


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About