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

Ok, assuming that the arrays will be mapped element for element without mixing and matching, you can do something like this:

use strict; use warnings; my @array1 = ('A','B','C','D'); my @array2 = ('1','2','3','4'); my %hash1; foreach my $key (@array1){ $hash1{$key} = shift(@array2); } for my $keys ( sort(keys %hash1 )) { my $value = $hash1{$keys}; print "$keys => $value\n"; }
Hope this helped. Regards, Jeff

"Every time Linux boots, a penguin gets its wings"

  • Comment on Re: How to make a hash out of two arrays,one with keys and other with values?
  • Download Code

Replies are listed 'Best First'.
How do I delete the first value from this hash?Kindly help!!
by sun@icgeb (Initiate) on Jun 30, 2009 at 11:41 UTC
    I have this hash and I need to normalise it.But problem is that it is taking the value of first key i.e. '' as minimum value.I want to delete this first key-value pair.How do I go about it?Please help!! $VAR1 = { '' => undef, 'D ' => '4.76', 'S ' => '4.50', 'I ' => '3.95', 'T ' => '4.35', 'K ' => '4.36', 'C ' => '4.65', 'P ' => '4.44', 'Y ' => '4.60', 'R ' => '4.38', 'E ' => '4.29', 'V ' => '3.95', 'N ' => '4.75', 'H ' => '4.63', 'G ' => '3.97', 'Q ' => '4.37', 'M ' => '4.52', 'F ' => '4.66', 'L ' => '4.17', 'A ' => '4.35', 'W ' => '4.70' }; Thanks in advance!!