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?
#删除了dino和fred@array = qw(pebbles dino fred barney betty); @removed = splice @array,2,qw(wilma);
#@removed 为 qw(dino fred)
#@array 为 qw(pebbles wilma barney betty)
4
#不删除元素 @removed = qw()@array = qw(pebbles dino fred barney betty); @removed = splice @array,qw(wilma);
#@array 为 qw(pebbles wilma dino fred barney betty)
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |