创建从一个数组表密钥的哈希表 - perl的 [英] Create a Hash table with keys from an array table - perl
本文介绍了创建从一个数组表密钥的哈希表 - perl的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建一个哈希表与数组表来钥匙?
How can i create a hash table with keys coming from an array table ?
我有了这个数组:我@array =(车,公交,自行车)
;
和我需要有一个这样的哈希值:
and I need to have a hash like that:
my %h = ( "car" => "1",
"bus" => "2",
"bike" => "3" );
感谢
推荐答案
您可以使用hash切片与键/值来填充它,
You can use hash slice to populate it with keys/values,
my @array = ("car","bus","bike");
my %h;
@h{@array} = 1 .. @array;
这篇关于创建从一个数组表密钥的哈希表 - perl的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文