Hash from two arrays: Difference between revisions
Content added Content deleted
(Added EchoLisp) |
(→{{Header|Perl 6}}: modernize) |
||
Line 1,056:
=={{header|Perl 6}}==
{{works with|rakudo|2015-09-13}}
<lang perl6>my @keys = <a b c d e>;
my @vals = ^5;
my %hash = flat @keys Z @vals;</lang>
or using the "zipwith" metaoperaotr on the <tt>=></tt> pair composer:
<lang perl6>my @v = <a b c d e>;
my %hash = @v Z=> @v.keys;</lang>
Line 1,071 ⟶ 1,072:
%hash{@keys} = @vals;</lang>
To create an anonymous hash value
<lang perl6>
All of these zip forms trim the result to the length of the shorter of their two input lists. If you wish to enforce equal lengths, you can use a strict hyperoperator instead:
<lang perl6>{ @keys »=>« @values }</lang>
|