The following works for me just fine under perl 5.10 and 5.14:
use strict;
use Data::Dumper;
my @array= qw(foo 42 bar);
my %hash;
@{ $hash{key} } = @array;
$hash{key} = [ @array ]; #same as above line
print Dumper(\%hash,$hash{key}[1]);
outputs (your order may vary):
$VAR1 = {
'key' => [
'foo',
'42',
'bar'
]
};
$VAR2 = '42';
I prefer the @{ $hash{key} }
syntax because you can push/pop with it, i.e.
push @{ $hash{key} }, "value";
which is surprisingly handy (for me anyway)
also, with this syntax you are copying the array and not just putting a reference to it, meaning you can change the original array without impacting the hash