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

数组 – 如何获取数组的最后一个元素并显示其余元素?

发布时间:2020-12-15 23:25:53 所属栏目:大数据 来源:网络整理
导读:如何获取数组的最后一个元素并显示其余元素? 像这样 : @myArray = (1,1,2); 预期产量: SomeVariable1 = 22222SomeVariable2 = 2 解决方法 # print last elementprint $myArray[-1];# joined rest of the elementsprint join "",@myArray[0 .. $#myArray-1
如何获取数组的最后一个元素并显示其余元素?

像这样 :

@myArray = (1,1,2);

预期产量:

SomeVariable1 = 22222
SomeVariable2 = 2

解决方法

# print last element
print $myArray[-1];

# joined rest of the elements
print join "",@myArray[0 .. $#myArray-1] if @myArray >1;

如果你不介意修改数组,

# print last element
print pop @myArray;

# joined rest of the elements
print join "",@myArray;

(编辑:李大同)

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

    推荐文章
      热点阅读