Slices are your friend!
Notice for this to work with 'use strict' (and you wouldn't *dare* not use 'use strict', would you?), you can't declare AND initialize the hash in the same statement.
And for those of you that wonder what happens if the length of
@a is unequal to that of
@b (which was me, up until a few minutes ago), if
@a is longer, the values that exist at positions greater than the length of
@b will be inserted into hash as keys, and the value set to undefined. If
@b is longer than
@a, values that exist at positions greater than the length of
@a are discarded/ignored.
#!/usr/local/bin/perl -w
use strict;
use Data::Dumper;
{
my @a = qw(one two three four);
my @b = qw(1 2 3 4);
my %hash = ();
@hash {@a} = @b;
print Dumper ([\%hash]);
}
$VAR1 = [
{
'three' => 3,
'two' => 2,
'one' => 1,
'four' => 4
}
];
--Chris
e-mail jcwren