加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何将两个数组分配给Perl中的散列?

发布时间:2020-12-15 21:24:10 所属栏目:大数据 来源:网络整理
导读:我有两行大代码的代码行(所以不能把它写入一个哈希),我想与一个哈希连接。 例如,$ array1 [0]成为键,$ array2 [0]成为值,等等到$ array1 [150],$ array2 [150]。 任何想法我如何做到这一点? 解决方法 您可以在单个作业中执行此操作: my %hash;@hash{@
我有两行大代码的代码行(所以不能把它写入一个哈希),我想与一个哈希连接。

例如,$ array1 [0]成为键,$ array2 [0]成为值,等等到$ array1 [150],$ array2 [150]。

任何想法我如何做到这一点?

解决方法

您可以在单个作业中执行此操作:
my %hash;
@hash{@array1} = @array2;

这是一个常见的成语。从perldoc perldata on slices:

If you’re confused about why you use
an ‘@’ there on a hash slice instead
of a ‘%’,think of it like this. The
type of bracket (square or curly)
governs whether it’s an array or a
hash being looked at. On the other
hand,the leading symbol (‘$’ or ‘@’)
on the array or hash indicates whether
you are getting back a singular value
(a scalar) or a plural one (a list).

当我看到其中的一个,我看到一个拉链的心理形象…

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读