On 06/13/2014 08:15 PM, Kamil Kułaga wrote: > Ok got it. But solution is neither more readable nor faster (IMHO only > -> I didn't benchmark it) > > > class A { has $.a; has $.b }; > my @array = A.new(a=>'a', b=>'11'), > A.new(a=>'a', b=>'22'), > A.new(a=>'v', b=>'33'), > A.new(a=>'w', b=>'44'), > A.new(a=>'v', b=>'55'); > > my %h = @array.map({ > my $var = .a; > $var => %(@array.grep({.a eq $var}).map({.b => $_})) > }); > > say %h<a>.perl; > > my %hash; > for @array -> $elem { > %hash{$elem.a}{$elem.b} =$elem; > } > > > say "Reference\n" ~ %hash<a>.perl;
Dear Kamil, the method "categorize", as specced in http://perlcabal.org/syn/S32/Containers.html#categorize will allow you to return a parcel from the "categorization" you provide (such as -> $_ { (.a, .b) }) and build a multi-leveled hash. Sadly, I wasn't able to make it work right away. Cheers, - Timo
signature.asc
Description: OpenPGP digital signature