in reply to How to make a hash out of two arrays,one with keys and other with values?

Very simply:

my %hash; @hash{@Arrayone} = @Arraytwo;

See hash slices in perldata.

You could also do it in one statement with the help of map.

my %hash = map { $Arrayone[$_] => $Arraytwo[$_] } 0..$#Arrayone;

Replies are listed 'Best First'.
Re^2: How to make a hash out of two arrays,one with keys and other with values?
by educated_foo (Vicar) on Jun 30, 2009 at 13:44 UTC
    And, as is often the case, less ops mean more win:
    #!/usr/bin/env perl use Benchmark 'cmpthese'; @k = 1..1000; @v = 1..1000; cmpthese(0, { map => 'my %h1 = map { $k[$_], $v[$_] } 0..$#k', for => 'my %h2; $h2{$k[$_]} = $v[$_] for 0..$#k', slice => 'my %h3; @h3{@k} = @v', }); __END__ Rate map for slice map 657/s -- -44% -65% for 1174/s 79% -- -38% slice 1884/s 187% 60% --