Assign array to hash as value

Hello, I need to assign the whole array to a hash, but it does not get what I want.
These only print out “c” but not a b c which is what I want.


my @arr = (a, b, c);
my $h = { v=> \\@arr };
print "@{$h->{v}}";

Thank you

Your code should work. If it prints ‘c’ instead of ‘a b c’ I think you may have tried different code than you posted. But if you are using “strict” (and you should) the array can not be constructed with barewords (unquoted strings):

use strict;
use warnings;
my @arr = (a, b, c);
my $h = { v=> \\@arr };
print "@{$h->{v}}";

should be:

use strict;
use warnings;
my @arr = qw(a b c);
my $h = { v=> \\@arr };
print "@{$h->{v}}";

Thanks for the reply, it works now. I don’t know why it didn’t work previously, it just print out c. I lost the code already after editing.