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

Perl 防"健忘“笔记 (splice 函数)

发布时间:2020-12-15 23:53:27 所属栏目:大数据 来源:网络整理
导读:splice 操作数组 (举例来自《perl 语言入门》) @removed ? = ? ? splice @array,?1,? ? ?2,? ? ? ? qw(wilma dxxu); ?删除元素的数组 ? ? ? ? ? ? 数组 ? 位置 ?长度 ? ? ? ?增加的数组元素 使用方法 1 @array = qe(pebbles dino fred barney betty);@remo
splice 操作数组 (举例来自《perl 语言入门》)

@removed ? = ? ? splice @array,?1,? ? ?2,? ? ? ? qw(wilma dxxu);
?删除元素的数组 ? ? ? ? ? ? 数组 ? 位置 ?长度 ? ? ? ?增加的数组元素


使用方法

1
@array = qe(pebbles dino fred barney betty);
@removed = splice @array,2;


#@removed 为 qw(fred barney betty)
#@array 为 qw(pebbles dino)


2?
@array = qw(pebbles dino fred barney betty);
@removed = splice @array,1,2;


#删除dino与fred两个元素
#@removed变成 qw(dino fred)
#@array 为 qw(pebbles barney betty)


3?
@array = qw(pebbles dino fred barney betty);
@removed = splice @array,2,qw(wilma);


#删除了dino和fred
#@removed 为 qw(dino fred)
#@array 为 qw(pebbles wilma barney betty)


4
@array = qw(pebbles dino fred barney betty);
@removed = splice @array,qw(wilma);


#不删除元素 @removed = qw()
#@array 为 qw(pebbles wilma dino fred barney betty)

(编辑:李大同)

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

    推荐文章
      热点阅读