Is there an elegant/efficient way to build a hash from 2 arrays :
Because of the list nature of hash, I thought I could do that with a zip-like function which unfortunately does not exists in the standard Perl dist. (or it's really well hidden).
I finally came up with this :
%h = (); @keys = qw/a b c/; @values = qw/foo bar baz/; $h{$k} = $v while defined($k = pop @keys) && defined($v = pop @values) +;
And I just realized that under use strict I must declare $k and $v outside the while to make it work... Great. Have you got something better ?
In reply to Making a hash with lists by knarf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |