use strict; use Data::Dumper; my @array1 = qw/ a b c d e /; my @array2 = qw/ 1 2 3 4 5 /; my $hash = build_hash(\@array1, \@array2); print Dumper($hash); # ----------------------------------------------------------- =pod =head1 FUNCTION sub build_hash ( \@array1, \@array2 ) =head1 SYNOPSIS my $hash = build_hash ( \@array1, \@array2 ); =head1 DESCRIPTION The function 'build_hash' takes 2 array references and returns reference to a hash. The hash is build by taking the elements from the first array as keys, and the corresponding elements from the second array as values. =cut # ----------------------------------------------------------- sub build_hash { my ($array1, $array2) = @_; return undef if $#$array1 ne $#$array2; # return \%{{map{$array1[$_]=>$array2[$_]}0..$#$array1}}; my %hash; # thanks ysth, yes I knew something was not right # with my map, I just couldn't remember the syntax # in the morning. :-) @hash{@$array1} = @$array2; return \%hash; }