数组 – 赋值中的Perl“上下文”
发布时间:2020-12-16 06:21:04 所属栏目:大数据 来源:网络整理
导读:作为Perl的新手,我只是不明白以下结果背后是什么样的哲学: $cnt1 = @arr; # this gives the length of the array 'arr'$cnt2 = @arr[ @indices_arr ]; # this gives the last element of the @arr[ @indices_arr ]; 有人能解释两者之间的区别吗? 解决方法
作为Perl的新手,我只是不明白以下结果背后是什么样的哲学:
$cnt1 = @arr; # this gives the length of the array 'arr' $cnt2 = @arr[ @indices_arr ]; # this gives the last element of the @arr[ @indices_arr ]; 有人能解释两者之间的区别吗? 解决方法
从
perldoc perldata 开始:
和:
和:
@arr是一个数组; @arr [@indices_arr]是一个数组切片. 至于背后的哲学:列表和数组在Perl中是不同的数据类型,具有不同的行为(不要被切片中使用的@sigil抛出,切片是列表,而不是数组).有关两者之间差异的深入解释,请参见Arrays vs. Lists in Perl: What’s the Difference? . (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |