parse string with pairs of values into hash the Perl6 way
解析下面的文本, 将其转换为散列:
width=13
height=15
name=Mirek
Answer1
my $text = "width=13\nheight=15\nname=Mirek";
$text ~~ / [(\w+) \= (\N+)]+ %% \n+ /;
my %params = $0>>.Str Z=> $1>>.Str;
Answer2
my %params = $text.comb(/\w+\=\N+/)>>.split("=").flat;
Answer3
my %params = $text.split("\n")>>.split("=").flat;
Answer4
my %params = $text.lines>>.split("=").flat;
怎么得到散列的元素个数?
How to get the count of no. of keys in a perl 6 %HASH?
%hash.elems