Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy array to hash

Tags:

perl

I'm trying to copy an array to a hash, such that each element of the array is a key, followed by an empty value.

my %questions = map { @u_list => $_ } @u_list;

This only prints out

=>

I see on perldoc this idiom:

     %hash = map { get_a_key_for($_) => $_ } @array;

But I cannot figure out how to set the keys. I want the keys to be each element in the array.

like image 717
Jonathan Dewein Avatar asked May 31 '26 05:05

Jonathan Dewein


1 Answers

Super confusing but functional answer:

@questions{@u_list}=();

This is using the hash slice syntax to specify a set of hash keys..

like image 123
evil otto Avatar answered Jun 02 '26 06:06

evil otto