Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Perl中将数组另外映射到现有哈希_Perl_Hash_Hashmap - Fatal编程技术网

在Perl中将数组另外映射到现有哈希

在Perl中将数组另外映射到现有哈希,perl,hash,hashmap,Perl,Hash,Hashmap,如何使用映射在现有哈希(如推入式数组)中添加元素 如果我这样做: %existing_hash = map { $_ => 1 } @new_elements; 这将重置%existing\u散列。请尝试: %existing_hash = (%existing_hash, map { $_ => 1 } @new_elements); 尝试: 我想我应该用简单的方法: $existing_hash{$_} = 1 for @new_elements; 但您也可以使用散列切片:

如何使用映射在现有哈希(如推入式数组)中添加元素

如果我这样做:

%existing_hash = map { $_ => 1 } @new_elements;
这将重置%existing\u散列。

请尝试:

%existing_hash = (%existing_hash, map { $_ => 1 } @new_elements);
尝试:


我想我应该用简单的方法:

$existing_hash{$_} = 1 for @new_elements;
但您也可以使用散列切片:

@existing_hash{@new_elements} = (1) x @new_elements;

我想我应该用简单的方法:

$existing_hash{$_} = 1 for @new_elements;
但您也可以使用散列切片:

@existing_hash{@new_elements} = (1) x @new_elements;

您的第一个解决方案也很好,看起来很简单,谢谢您的好主意。您的第一个解决方案也很好,看起来很简单,谢谢您的好主意。