http://www.perlmonks.org?node_id=480718


in reply to Hash and arrays

You mean like this?
my @k = ("a", "b", "c"); my @v = (1, 2, 3); my %h = map { $k[$_] => $v[$_] } (0..$#k);


holli, /regexed monk/

Replies are listed 'Best First'.
Re^2: Hash and arrays
by thinker (Parson) on Aug 04, 2005 at 08:48 UTC

    Or, in a similar way, use a hash slice to populate the hash

    #!/usr/bin/perl use strict; use warnings FATAL => "all"; use Data::Dumper; my @k = ("a", "b", "c"); my @v = (1, 2, 3); my %h; @h{@k} = @v; print Dumper \%h; __END__ output $VAR1 = { 'c' => 3, 'a' => 1, 'b' => 2 };

    cheers

    thinker